Mình đang học C tới phần link list. Nhưng khi viet code xong (trên Dev C++) thì nó không chạy, mọi người có thể giúp mình giải quyết với, mọi người copy code chạy thử rồi chỉnh giúp mình với
#include<stdio.h>
#include<stdlib.h>
#include<windows.h>
struct node{
int data;
struct node *pNext;
};
typedef struct node node;
struct list{
node *pHead;
node *pTail;
};
typedef struct list list;
int CreateList (list &l){
l.pHead=NULL;
l.pTail=NULL;
}
node *CreateNode(int x){
node *p=(node *)malloc(sizeof(node));
p->data=x;
p->pNext=NULL;
return p;
}
int AddNodeEnd(list &l,node *p){
if(l.pHead=NULL){
l.pHead=l.pTail=p;
}
else{
l.pTail->pNext=p;
l.pTail=p;
}
}
int OutPut(list l){
for(node *k=l.pHead;k!=NULL;k=k->pNext){
printf("%d",k->data);
}
}
int main(void){
int x;
list l;
CreateList(l);
printf("\t\tCreate link list\n");
for(;;){
printf("Input data of new node:");
scanf("%d",&x);
if(x!=0){
node *p=CreateNode(x);
AddNodeEnd(l,p);
}
else{
break;
}
}
printf("Link list: ");
OutPut(l);
return 0;
}