头插法创建无头结点单链表
#include <iostream>
using namespace std;
/*
*writer:yaojinhui
*/
#define Eletype char
typedef struct LNode
{
Eletype data;
struct LNode *next;
}LNode,*Linklist;
void createList(Linklist &L)
{
LNode *q;
L=NULL;
char ch;
while(1)
{
cin>>ch;
if(ch=='#')
break;
q=new LNode;
q->data=ch;
q->next=L;
L=q;
}
}
void print(Linklist L)
{
LNode *p;
p=L;
while(p)
{
cout<<p->data;
p=p->next;
}
cout<<endl;
}
int main() {
Linklist L;
createList(L);
print(L);
return 0;
}