//shang4 设有一个双链表 设计一个算法查找第一个元素为x的结点,并将与其后的结点进行交换//
#include "stdlib.h"
#include "stdio.h"
#define n 9
typedef int Elemtype;
typedef struct node
{
Elemtype date;
struct node *next;
struct node *prior;
}*list;
int listinit(list la)
{
la=(list)malloc(n*sizeof(list));
if(!la)
// printf("error!/n");
return 0;
la->next=NULL;
}
int listlocate(list la,Elemtype i, Elemtype x)
{
//struct node *p;
list p;
int j=0;
p=(list)malloc(sizeof(list));
p=la->next;
while(j<n&&P->date!=x)
{
p=p->next;
j++;
}
if(!p||j>i-1)
//return error;
//if(p->date==x)
return 0;
printf("%d",i);
p->prior->next=p->next;
p->next->prior=p->prior;
}
return ok;
main()
{
list la,*p;
//struct node *p;
int a,b,n,i,j;
scanf("%d",&x);
for(j=0;j<n;j++)
scanf("%d",&la->date);
a=listinit(la);
b=listlocate(la,i,x);
printf("%d",b);
}