ltbaogt
Tổng số bài gửi : 18 Join date : 01/01/2010
| Tiêu đề: Please find some error in this program!! Tue Apr 13, 2010 10:28 pm | |
| - Code:
-
#include<stdio.h> #include <conio.h> // maybe there are some library needn't #include <string.h> #include <iostream.h> struct node { int x; node *pnext; }; typedef node NODE; node* TaoNode(int x) { node* pnode=new node; if(pnode==NULL) { return NULL; } pnode->x=x; pnode->pnext=NULL; return pnode; } bool ThemDau(node* &phead,int data) { node *pnode=TaoNode(data); if(phead==NULL) { phead=pnode; } pnode->pnext=phead; pnode->x=data; phead=pnode; return true; } node* XoaDau(node* &phead) { node* pnode; if(phead==NULL) { printf("Danh Sach Rong"); } else { pnode=phead; return pnode; phead=NULL; } return pnode; } node* XoaCuoi(node* phead) // Where is error in this function ? { // please check it for me and find some error ! node* pdel; //Notice: This function still runs normally but it shows to you a error table on the Dos Screen if(phead==NULL) { return NULL; } if(phead->pnext==NULL) { pdel=phead; return pdel; phead=NULL; } node* pcur; { pdel=phead; while(pdel->pnext->pnext!=NULL) { pdel=pdel->pnext; } pcur=pdel->pnext; pdel->pnext=NULL;
return pcur; } } void main() { int n; printf("Nhap so Node: "); scanf("%d",&n); node* pnode=NULL; for(int i=n;i>0;i--) { ThemDau(pnode,i); printf("%d\n",pnode->x); printf("%d\n",pnode->pnext); } printf("\n") ; node* pdel=XoaDau(pnode); printf("Pop :"); printf("%d\n",pdel->x); printf("%d\n",pdel->pnext); node *ptail=XoaCuoi(pnode); printf("%d\n",ptail->x); } | |
|