link mylist(link aa)
{
int Data[2][10]={{3,9,25,5,7,26,65,80,2,6},{1050,3850,1000,5670,2250,9650,2380,1700,3000,2000}};
link pa=aa;
for(int i=0;i<10;i++)
{
link p=aa;
p=(link)malloc(sizeof(dulnode));
p->Number=Data[0][i];
p->Data=Data[1][i];
p->next = aa;aa->next = p;
p->prior=pa;pa->next=p;
pa=p;
}
pa=aa;
for(int j=0;j<10;j++)
{printf("%d\n",pa->next->Data);pa->next=pa->next->next;}
return aa;
}
void List_Search(link Head,int Key)
{
link pa=Head;
int i=1;
while(pa->next!=Head)
{
if(pa->next->Number==Key)
{
printf("%d ",pa->Data);
printf("%d \n",i);
return;
}
pa=pa->next;
i++;
}
pirntf("NO FOUND\n");
}
void freelist(link Head)
{
link s;
link pa=Head;
while(pa->next!=Head)
{
s=pa->next;
pa->next->next->prior=pa;
pa->next=pa->next;
free(s);
}
}
void main()
{
int n;
link head;
head=(link)malloc(sizeof(dulnode));
head->next=head->prior=head;
head = mylist(head);
mylist(head);
printf("请输入位序:");
scanf("%d",&n);
if(n==0) freelist(head);
List_Search(head,n);
}
#include
#include
#define NULL 0
struct list
{
int Number;
int Data;
struct list* prior;
struct list* next;
};
typedef struct list dulnode;
typedef dulnode* link;
link mylist(link head)
{
int Data[2][10]={{3,9,25,5,7,26,65,80,2,6},{1050,3850,1000,5670,2250,9650,2380,1700,3000,2000}};
//link pa=head;
head->Number=Data[0][0];
head->Data=Data[1][0];
link p=head;
for(int i=1;i<10;i++)
{
p->next=(link)malloc(sizeof(dulnode));
p->next->prior=p;
p=p->next;
p->Number=Data[0][i];
p->Data=Data[1][i];
//p->next->prior=p->prior->next=p;
//pa->next=p;p->prior=pa;
//pa->next->prior=p;p->next=pa->next;
//p=p->next;
}
p->next=head;
head->prior=p;
p=head;
for(int j=0;j<10;j++)
{printf("%d\n",p->Data);p=p->next;}
return head;
}
void List_Search(link Head,int Key)
{
link pa=Head;
int i=1;
while(pa->Number!=Key&&i<11)
{
pa=pa->next;
i++;
}
if(pa->Number!=Key)printf("NO FOUND\n");
else
{
printf("%d ",pa->Data);
printf("%d ",i);
}
}
void freelist()
{
link s;
link pa=s->next;
while(pa)
{
pa->prior->next=pa->next;
pa->next->prior=pa->prior;
free(pa);
pa=pa->next;
}
}
void main()
{
int n;
link head;
head=(link)malloc(sizeof(dulnode));
//head->next->prior=head->prior->next=head;
//head->next=head->prior=head;
mylist(head);
printf("请输入位序:");
scanf("%d",&n);
//if(n==0) freelist();
List_Search(head,n);
}