-2
我得到了我的方式...现在正在工作...没有全局指针..检查。 。在c中写一个函数,我们可以在其中添加多个单独列表... [已解决]
#include<stdio.h>
#include<conio.h>
struct list
{
int n;
struct list *next,*prev;
};
typedef struct list list;
list *create(list *head)
{
list *tmp,*cur;
tmp=(list *)malloc(sizeof(list));
printf("\nEnter Value.. :: ");
scanf("%d",&tmp->n);
tmp->next=NULL;
tmp->prev=NULL;
if(head==NULL)
{
head=tmp;
cur=tmp;
}
else
{
cur=head;
while(cur->next!=NULL)
cur=cur->next;
cur->next=tmp;
tmp->prev=cur;
}
return head;
}
void disp(list *head)
{
list *cur;
if(head==NULL)
printf("\n\nEmpty List..!!!");
else
{
printf("\n\nLIST ::\t");
cur=head;
while(cur!=NULL)
{
if(cur->next!=NULL)
printf(" %d =>",cur->n);
else
printf(" %d ",cur->n);
cur=cur->next;
}
}
}
void main()
{
list *first=NULL,*second=NULL;
int ch;
while(ch!=0)
{
clrscr();
printf("\n\t********** SIMPLE DOUBLY LINKED LIST PROGRAM **********");
printf("\n\n\t1. Create First List...");
printf("\n\t2. Create Second List...");
printf("\n\t3. Display Both Lists...");
printf("\n\t0. Exit...");
printf("\n\tEnter Your Choice.. :: ");
scanf("%d",&ch);
switch(ch)
{
case 1: first=create(first);
disp(first);
break;
case 2: second=create(second);
disp(second);
break;
case 3: disp(first);
disp(second);
break;
}
getch();
}
}
你的问题不是很清楚。请张贴您的代码,并更清楚地解释您的代码的确切问题:至少,输入是什么,预期的和实际的输出。 – 2011-05-19 15:28:12
您的问题尚不清楚,请重新填写。 – Pepe 2011-05-19 15:28:24
这个问题很不清楚。请尝试再次提问并解释你想要这个“添加”功能。 – 2011-05-19 15:29:00