temp->next=NULL;
current->next=temp;/*当前节点的后驱指向新节点*/
current=temp;/*当前节点为链表尾节点*/
}
return head;
}
/*创建双链表*/
DNode* DoubleList(DNode*head)
{
if(NULL== head)//分配头节点空间
head=(DNode*)malloc(sizeof(DNode)) , head->prev=NULL ,head->next=NULL;
DNode*current=head ,*temp;
char ch;
while(1)
{
cout<<"\n input elem:";
cin>>ch;
if('#' == ch)/*#结束输入*/
break;
temp=(DNode*) malloc (sizeof(DNode) );
temp->elem=ch;
temp->next=NULL;
current->next=temp;/*当前节点的后驱指向新节点*/
temp->prev=current;/*新节点的前驱指向当前节点*/
current=temp;/*当前节点为链表尾节点*/
}
return head;
}
/*创建循环链表*/
Node* CycleList(Node*head)
{
if(NULL== head)/*分配头节点空间*/
评论1
最新资源