DSLK don
// abbc.cpp : Defines the entry point for the console application.
//DSLK don
#include "stdafx.h"
struct nodelist
{
int info;
nodelist *pNext;
};
struct list
{
nodelist *pHead;
nodelist *pTail;
};
/*void ReadFile(list &l)
{
int a[100];
FILE *f = fopen("input.txt","rt");
while(!feof(f))
{
fscanf(f,"%d",&temp);
nodelist *p= GetNode(temp);
AddHead(l,p);
}
fclose(f);
}
*/
void Init(list &l)
{
l.pHead = l.pTail= NULL;
}
nodelist *GetNode(int x)
{
nodelist *p=new nodelist;
if(p==NULL)
return NULL;
p->info=x;
p->pNext=NULL;
return p;
}
void AddHead(list &l, nodelist*p)
{
if(l.pHead==NULL)
l.pHead=l.pTail=p;
else
{
p->pNext=l.pHead;
l.pHead=p;
}
}
void AddTail(list&l, nodelist *p)
{
if(l.pHead==NULL)
l.pHead=l.pTail=p;
else
{
l.pTail->pNext=p;
l.pTail=p;
}
}
nodelist *GetHead(list &l)
{
if(l.pHead==l.pTail==NULL)
return NULL;
else if(l.pHead==l.pTail)
{
nodelist *p =l.pHead;
l.pHead=l.pTail=NULL;
return p;
}
else
{
nodelist *p=l.pHead;
l.pHead = l.pHead->pNext;
p -> pNext = NULL;
return p;
}
}
void ReadFile(list &l)
{
//int a[100];
FILE *f = fopen("input.txt","rt");
while(!feof(f))
{
fscanf(f,"%d",&temp);
nodelist *p= GetNode(temp);
//AddHead(l,p);
AddTail(l,p);
}
fclose(f);
}
void PrintList(list l)
{
for(nodelist *p =l.pHead;p;p=p->pNext)
printf("%d",p->info);
}
int _tmain(int argc, _TCHAR* argv[])
{
//ReadFile();
list l;
Init(l);
ReadFile(l);
/*printf("nhap gt n: ");
scanf("%d",&temp);
nodelist *p= GetNode(temp);
AddHead(l,p);
//AddTail(l,p);*/
PrintList(l);
return 0;
}
Bạn đang đọc truyện trên: AzTruyen.Top