#ifndef _LINKLIST
#define _LINKLIST
#include
using namespace std ;
struct node
{
int data ;
struct node *next ;
};
typedef struct node *PLIST;
typedef struct node NODE;
/创建链表,并初始化链表元素/
PLIST createList_link()
{
PLIST head ,tail ,temp;
int elem = -1;
head = new NODE; //初始化头结点
if( head == NULL)
{
cout<<“分配空间失败,链表创建失败”<<endl;
return NULL;
}
head->next = NULL;
tail = head ;
while(1)
{
cin >> elem ;
if(elem == 0 ) break ;
temp = new NODE ;
if(temp == NULL)
{
cout<<“分配空间失败,链表创建失败”<<endl;
break ;
}
temp->data = elem ;
temp->next = NULL ;
tail->next = temp ;
tail = temp;
}
return head ;
}
void printList_link(PLIST head )
{
/在此处完成任务,输出head为表头的单链表数据元素/
//begin
if(head->next)
{
PLIST p=head->next;
cout<data<<" “;
while(p->next)
{ p=p->next;
cout<data<<” ";}
}
//end
}
void insertDataTail(PLIST head , int insData )
{
/在此处完成任务,在head为表头的单链表表尾插入数据元素insData/
//begin
PLIST p,s;
p=head;
p=p->next;
while(p->next!=NULL)
{
p=p->next ;
}
s=(PLIST)malloc(sizeof(struct node));//生成新结点
s->data =insData;
s->next =NULL;
p->next =s;
//end
}
#endif