#include<iostream>
#include<string>
#include<cassert>
using namespace std;
class node
{
public:
int data;
node * next;
// int * head;
// int * tail;
};
node * insertafter(int data,node * n=NULL)
{
node * a=new node;
assert(a!=NULL);
a->data=data;
if(n==NULL)
{
a->next=NULL;
cout<<"link head created"<<endl;
//return a;
}
else //if(n->next==null)
{
a->next=n->next;
n->next=a;
//return a;
cout<<"link data inserted"<<endl;
}
return a;
//delete a;这个a怎么处理?放着不管?在return后面执行delete a会不会被执行?还是不用delete,返回的指针就是这
//个a,不会造成内存问题?
}
void printlink(node *head)
{
assert(head!=NULL);
node *p=head;
while(p!=NULL)
{
cout<<p->data<<" ";
p=p->next;
}
}
void main()
{
node *a =insertafter(0);
node *b =insertafter(1,a);
node *c =insertafter(2,b);
node *d =insertafter(3,a);
printlink(a);
}