链表后插法

#include <iostream>


using namespace std;


struct LinkNode 
{
int data;
LinkNode *next;
};


void init(LinkNode *&head)
{
head=new LinkNode;
head->next=NULL;
}


void create(LinkNode *&head)
{
int i;
cin>>i;
if(i==0)
head->next=NULL;
else
{
head->next=new LinkNode;
head->next->data=i;
create(head->next);
}
}


void show(LinkNode *head)
{
if(head->next)
{
cout<<head->next->data<<" ";
show(head->next);
}
}


int main()
{
LinkNode *head;
init(head);
create(head);
show(head);

return 0;
}

猜你喜欢

转载自blog.csdn.net/wrc_nb/article/details/80207578