-
17-12-2008, 03:59 PM #1Junior Member
- 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(); }
View more random threads:
- cần các thánh thông não
- Hix! Lỗi nhỏ trong cách sử dụng thư viện string!
- Giải một số bài tập về mảng một chiều.
- Không dùng được các hàm trong C
- Có phải lỗi của DevC khi lập trình về ngăn xếp???
- Stack,Queue
- giup minh tinh bay nay voi
- %*d , %lf và %*s có nghĩa như thế nào ?
- class hình học.nhờ các thầy sửa giúp.
- Bài quản lý nhân viên, giúp mình tìm lỗi bài này với?
-
17-12-2008, 04:04 PM #2Junior Member
- Ngày tham gia
- Sep 2015
- Bài viết
- 0
Đem đưa code vào tag đi, đọc rối mắt quá.
-
17-12-2008, 06:35 PM #3Junior Member
- Ngày tham gia
- Sep 2015
- Bài viết
- 0
mình đưa code vào tag oy giải thích giùm mình với nhé
-
18-12-2008, 01:31 PM #4Junior Member
- Ngày tham gia
- Sep 2015
- Bài viết
- 0
sao ko ai giúp mình vậy hix hixT_T
-
18-12-2008, 02:46 PM #5Junior Member
- 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(); }
-
18-12-2008, 05:00 PM #6Junior Member
- 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^^
Dưới ánh nắng mặt trời đang lên, những đống pallet nhựa An Giang trải dài mênh mông như những bức tranh tự nhiên đầy sắc màu. Mỗi chiếc pallet nhựa không chỉ là một vật dụng thông thường mà còn là...
Pallet nhựa An Giang giao hàng...