题目详情

已知N个数已存入数组A[1…M]的前N个元素中(N<M),为在A[i](1≤i≤N)之前插入一个新数,应先(),以挪出一个空闲位置插入该数。

  • A.从A[i]开始直到A[l],每个数向后移动一个位置
  • B.从A[1]开始直到A[i],每个数向后移动一个位置
  • C.从A[i]开始直到A[N],每个数向前移动一个位置
  • D.从A[N]开始直到A[i],每个数间后移动一个位置

正确答案及解析

正确答案
D
解析

本题考查用顺序方式存储线性表元素的插入运算特点。数组A[1..M]元素的布局如下图所示。

初级程序员,历年真题,2006年下半年《程序员》真题

对于选项A,从A[i]开始直到A[1]的每个数向后移动一个位置,会将A[i+1]原来的值覆盖,挪出的空闲位置为A[1],显然不符合新元素插入在A[i]之前(即A[i-1]之后)的要求。

对于选项B,从A[1]开始直到A[i]的每个数向后移动一个位置,使A[2]的值被改为与A[1]相同,使A[3]的值被改为与A[2]相同,依此类推,A[i]的值等于A[i-1],即完成该操作后,元素A[1]到A[i]的值都相同(等于A[1])。

对于选项C,从A[i]开始直到A闪的每个数向前移动一个位置,使A[i-1]的值被改为A[i]的值,A[i]的值被改为A[i+1]的值,依此类推,A[N-1]的值为A[N]的值,相当于挪出来的空闲位置为A[N],显然不符合新元素插入在A[i]之前的要求。

对于选项D,从A[N]开始直到A[i]的每个数向后移动一个位置,使A[N]的值移入A[N+1], A[N-1]的值移入A[N],依此类推,A[i]的值移入A[i+1],这样挪出来的空闲位置为A[i],完成了将新元素插入在A[i-1]之后(即A[i]之前)的操作要求。

包含此试题的试卷

你可能感兴趣的试题

单选题

(  )is the process of transforming information so it is unintelligible to anyone but the intended recipient.

  • A.Encryption
  • B.Decryption
  • C.Security
  • D.Protection
查看答案
单选题

As each application module is completed,it undergoes(  )to ensure that it operates correctly and reliably.

  • A.unit testing
  • B.integration testing
  • C.system testing
  • D.acceptance testing
查看答案
单选题

(  )algorithm specifies the way to arrange data in a particular order.

  • A.Search
  • B.Random
  • C.Sorting
  • D.Merge
查看答案
单选题

After analyzing the source code,(  )generates machine instructions that will carry out the meaning of the program at a later time.

  • A.an interpreter
  • B.a linker
  • C.a compiler
  • D.a converter
查看答案
单选题

(  )can help organizations to better understand the information contained within the data and will also help identify the data that is most important to the business and future business decisions.

  • A.Data processing system
  • B.Big Data analytics
  • C.Cloud computing
  • D.Database management
查看答案

相关题库更多 +