// Nguyễn Tuấn Anh | MSV: CT030104 #include #include typedef struct Node{ int Data; struct Node* pNext; }Node; Node* Head; Node* Tail; Node* pNode; void createNode(int data){ pNode=(Node*)malloc(sizeof(Node)); if(pNode==NULL){ printf("Cap phat du lieu khong thanh cong !"); exit(0); } else{ pNode->Data=data; pNode->pNext=NULL; } } void addHead(int data){ if(Head==NULL){ Head=Tail=pNode; } else{ pNode->pNext=Head; pNode=Head; } } void addTail(int data){ if(Head==NULL){ Head=Tail=pNode; } else{ Tail->pNext=pNode; Tail=pNode; } } void input(){ FILE* f; int data; f=fopen("Data.txt","r"); while(!feof(f)){ fscanf(f,"%d",&data); createNode(data); addTail(data); } fclose(f); } void output(){ pNode=Head; printf("Du lieu duoc lay tu file la:\n"); while(pNode!=NULL){ printf("%d",pNode->Data); printf("\n"); pNode=pNode->pNext; } } int main(){ int Data; input(); output(); }