Code lập trình công nghệ thông tin

6 4 0
Code lập trình công nghệ thông tin

Đang tải... (xem toàn văn)

Thông tin tài liệu

Các dòng code lập trình chuyên nghiệp,có 6 trang và trình báy bố cục rõ ràng thuận tiện cho việc xem, Tài liệu gồm 29 trang hướng dẫn chi tiết Professional programming lines, has 6 pages and presents a clear layout for easy viewing

#include #include struct node { int info; struct node *next; }; typedef node *listnode; listnode *head; void init(listnode *head) { *head=NULL; } void insert_first(listnode *head,int x) { listnode p; p=new node; p->info=x; p->next= *head; *head=p; } void insert_last(listnode *head,int x) { listnode p,q; p=new node; p->info=x; p->next=NULL; if(*head==NULL) *head=p; else { q=*head; while(q->next!=NULL)q=q->next; q->next=p; } } void delete_first(listnode *head) { listnode q; if(*head!=NULL) { q=*head; *head=q->next; q->next=NULL; delete(q); } } void delete_last(listnode *head) { listnode q,r; if((*head)->next==NULL) { delete_first(head); return; } r=*head; while(r->next!=NULL) { q=r; r=r->next; } q->next=NULL;delete(r); } void output(listnode *head) { listnode p; p=*head; while(p!=NULL) { printf("%5d",p->info) ; p=p->next; } } int tong(listnode *head) { int t=0; listnode p; p=*head; while(p!=NULL) { t+=p->info; p=p->next; } return t; } listnode search(listnode *head,int key) { listnode q; q=*head; while((q!=NULL)&&(q->info!=key)) q=q->next; return q; } void main() { int chon,x,key; listnode *head; { clrscr; printf("\n Nhap danh sach"); printf("\n chen pt vao dau"); printf("\n chen phan tu vao cuoi"); printf("\n xoa pt cao dau"); printf("\n xoa phan tu vao cuoi"); printf("\n tinh tong"); printf("\n tim key"); printf("\n thoat"); printf("\n"); scanf("%d",&chon); switch(chon) { case 1: init(head); break; case 2: printf("\nNhap x:"); scanf("%d",&x); insert_first(head,x); output(head); break; case 3: printf("\nNhap x:"); scanf("%d",&x); insert_last(head,x); output(head); break; case 4: delete_first(head); output(head); break; case 5: delete_last(head); output(head); break; case 6: output(head); printf("\n Tong la %d",tong(head)); break; case 7: printf("\n nhap key:"); scanf("%d",&key); output(head); if((search(head,key)==NULL)) printf("\n ko tim thay %d",key); else printf("\n tim thay %d",key); break; case 8: break; } getch(); } while(chon!=8); }

Ngày đăng: 04/09/2023, 03:12

Tài liệu cùng người dùng

Tài liệu liên quan