Chào mừng đến với Diễn đàn lập trình - Cộng đồng lập trình.
Kết quả 1 đến 6 của 6
  1. #1
    Ngày tham gia
    Sep 2015
    Bài viết
    0

    bài tập phần danh sách liên kết help

    xem dùm mình đoạn code này sai chỗ nào mà mình in danh sách cứ thiếu phần tử đầu,giải thích dùm mình luôn mấy chỗ mình đánh dấu trong code nhe
    Mã:
    #include"conio.h"
    #include"stdio.h"
    #include"stdlib.h"
    typedef struct node
    {
            int info;
            node *pnext;
    };
    void khoitao_ds(node **first,node **last)//sao lại node **first ?
    {
         *first=*last=NULL;
    }
    void insert_ds(int k,node **first,node **last)
    {
         node *p;
         p=(node*)malloc(sizeof(node));
         p->info=k;
         p->pnext=NULL;
         if(*first==NULL)
             *first=*last=p;
         else
             {
                 (*last)->pnext=p;//chỗ này nữa (*last) ???
                 (*last)=(*last)->pnext;
             }
    }
    void nhap_ds(node **first,node **last)
    {
         int k;
         printf("
    cac ban nhap gia tri 0 de ket thuc ds:
    ");
         scanf("%d",&k);
         do
           {
               scanf("%d",&k);
               if(k!=0)
                  insert_ds(k,first,last);
           }
         while (k!=0);
    }
    void print_ds(node *first,char *s)
    {
         node *p;
         printf("%s",s);
         p=first;
         while(p!=NULL)
               {
                    printf("[%d] ",p->info);
                    p=p->pnext;
               }    
    }    
    main()
    {
          node *first,*last;
          khoitao_ds(&first,&last);
          nhap_ds(&first,&last);
          print_ds(first,"danh sach dc nhap vao la:");
          getch();
    }

  2. #2
    Ngày tham gia
    Sep 2015
    Bài viết
    0
    Đem đưa code vào tag đi, đọc rối mắt quá.

  3. #3
    mình đưa code vào tag oy giải thích giùm mình với nhé

  4. #4
    Ngày tham gia
    Sep 2015
    Bài viết
    0
    sao ko ai giúp mình vậy hix hixT_T

  5. #5
    Ngày tham gia
    Sep 2015
    Bài viết
    0
    Mã:
    #include"conio.h"
    #include"stdio.h"
    #include"stdlib.h"
    typedef struct node
    {
            int info;
            node *pnext;
    };
    void khoitao_ds(node **first,node **last)//day la con tro tro toi con tro dung de truyen tham bien.
    {
         *first=*last=NULL;
    }
    void insert_ds(int k,node **first,node **last)
    {
         node *p;
         p=(node*)malloc(sizeof(node));
         p->info=k;
         p->pnext=NULL;
         if(*first==NULL)
             *first=*last=p;
         else
             {
                 (*last)->pnext=p;//(*last)la con tro thuc su duoc truyen vao
                 (*last)=(*last)->pnext;
             }
    }
    void nhap_ds(node **first,node **last)
    {
         int k;
         printf("
    cac ban nhap gia tri 0 de ket thuc ds:
    ");
    	 // scanf("%d",&k); Thua dong nay nen ket qua sai
         do
           {
               scanf("%d",&k);
               if(k!=0)
                  insert_ds(k,first,last);
           }
         while (k!=0);
    }
    void print_ds(node *first,char *s)
    {
         node *p;
         printf("%s",s);
         p=first;
         while(p!=NULL)
               {
                    printf("[%d] ",p->info);
                    p=p->pnext;
               }    
    }    
    int main()
    {
          node *first,*last;
          khoitao_ds(&first,&last);
          nhap_ds(&first,&last);
          print_ds(first,"danh sach dc nhap vao la:");
          getch();
    }

  6. #6
    Ngày tham gia
    Sep 2015
    Bài viết
    0
    cám ơn bạn rất nhiều,mình hiểu òy^^

 

 

Quyền viết bài

  • Bạn Không thể gửi Chủ đề mới
  • Bạn Không thể Gửi trả lời
  • Bạn Không thể Gửi file đính kèm
  • Bạn Không thể Sửa bài viết của mình
  •