數據結構-鏈表


判斷題

1.在單向鏈表中,頭指針中存放的是頭結點的內容。

     T      F

2.單向鏈表中的每個結點都需要動態分配內存空間。

     T      F

3.通常使用結構的嵌套來定義單向鏈表結點的數據類型。

     T      F

4.用鏈表代替數組進行數據操作時,查詢更加方便。

     T      F

選擇題

1.以下程序的輸出結果是( )。

struct HAR
{int x, y; struct  HAR  *p;} h[2];
int main(void)
{ h[0].x=1; h[0].y=2;
  h[1].x=3; h[1].y=4;
  h[0].p=h[1].p=h;
  printf(“%d%d\n”,(h[0].p)->x,(h[1].p)->y);		
  return 0;		}
     A.12
     B.23
     C.14
     D.32

2.以下程序的輸出結果是( )。

struct NODE{ int num;  struct NODE  *next; };
int main(void)
{ struct NODE *p,*q,*r;
  p=(struct NODE*)malloc(sizeof(struct NODE));
  q=(struct NODE*)malloc(sizeof(struct NODE));
  r=(struct NODE*)malloc(sizeof(struct NODE));
  p->num=10; q->num=20; r->num=30;
  p->next=q;q->next=r;
  printf(“%d\n”,p->num+q->next->num);	
  return 0;		}
     A.10
     B.20
     C.30
     D.40

3.設有如下定義的鏈表,則值為7的表達式是()。

struct st{
      int n;
      struct st  *next;
} a[3] = {5, &a[1], 7, &a[2], 9, NULL}, *p = &a;
     A.p->n
     B.(p->n)++
     C.(++p)->n
     D.p->next->n

4.在一個單鏈表head中,若要在指針p所指結點后插入一個q指針所指結點,則執行()。

     A.p->next=q->next; q->next=p;
     B.q->next=p->next; p=q;
     C.p->next=q->next; p->next=q;
     D.1. q->next=p->next; p->next=q;

5.下面程序段輸入一行字符,按輸入的逆序建立一個鏈表。

struct node{
  char info;
  struct node *link;
} *top, *p;
char c;
top=NULL;
while((c=getchat())!='\n')
{  p=( struct node*)malloc(sizeof(struct node));
   p->info=c;
     (1分)   ;
   top=p;
}
     A.top->link=p
     B.p->link=top
     C.top=p->link
     D.p=top->link

6.若已建立下面的鏈表結構,指針p、q分別指向圖中所示結點,則不能將q所指結點插入到鏈表末尾的語句是( )。

1.jpg

     A.q->next=NULL; p=p->next; p->next=q;
     B.p=p->next; q->next=p->next; p->next=q;
     C.p=p->next; q->next=p; p->next=q;
     D.p=(*p).next; (*q).next=(*p).next; (*p).next=q;

填空題

1.下列函數用於將鏈表中各結點的數據依次輸出。

struct student {
    long data;
    struct student *next;
};
void print(struct student *head)
{
    struct student *p ;
    p=head;
    if(head != NULL)
        do {
            printf("%ld\n”, p->data);
                    ;
        } while ( );
}

2.已建立學生“英語”課程的成績鏈表(成績存於score域中,學號存於num域中), 下列函數用於輸出不及格學生的學號和成績,及補考學生人數。

void require(struct student *head)
{
    struct student *p;
    long x;
    if( head != NULL) {
        x=0;
                ;
        while(p != NULL) {
            if( ) {
                printf(”%7d %6.1f\n”, p->num, p->score);
                x++;
            }
            p = p->next;
        }
        printf(”%ld\n”, x);
    }
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM