#include
using namespace std;
typedef int elemtype;
struct lnode
{
lnode *next;
typedef data;
};
void initlist(lnode *& hl)
{
hl=new lnode;
hl->next=NULL;
}
elemtype getlist(lnode *& hl,int pos)
{
int i=0;
hl=hl->next;
while(hl!=NULL)
{
i++;
if(i==pos)break;
hl=hl->next;
}
return hl->data;
}
void traverlist(lnode *hl)
{
hl=hl->next;
while(hl!=NULL)
{
coutdatanext;
}
coutnext;
j++;
}
if(p==NULL)return 0;
lnode *newptr=new lnode;
newptr->data=item;
newptr->next=p->next;
p->next=newptr;
return 1;
}
/*bool DeleteList(lnode*&hl,intpos,ElemType &item)
{
lnode *p=GetList(hl,pos-1);
if( p==NULL ) return0;
lnode *q=p->next;
item=q->data;
p->next=q->next;
deleteq;
return1;
}*/
voidCreateList(lnode * &hl,int n)
{
lnode *ptr;
hl=new lnode ;
hl->next=NULL;
for(inti=n;i>0;i--)
{
ptr=new lnode ;
cin>>ptr->data;
ptr->next=hl->next; hl->next=ptr;
}
}
void main()
{
int a[10];
lnode *s;
initlist(s);
for(int i=0;i>a;
insertlist(s,1,a);
}
traverlist(s);
}
|