//#include "stdafx.h"
#include<iostream>
using namespace std;
struct Node
{
int data;
Node *next;
};
Node *rear;
void LinkList(int a[],int n)
{
Node *s;
int i;
rear=new Node; //建立空单链表
rear->next=rear;
for(i=0;i<n;i++)
{s=new Node; s->data=a[i]; //创建结点并赋值
s->next=rear->next ; //插入表尾中
rear->next=s;
rear=s;
}
}
int LinkListLDI(int x)
{
Node *p,*q;
if (rear->next!=rear)
{ p=rear->next;
q=p->next;
while (p!=rear)
if (q->data==x)
{ p->next=q->next;
if (q==rear) rear=p;
delete q;return x;
}
else {p=q;q=q->next;};
}
q=new Node;
q->data=x;
q->next=rear->next;
rear->next=q;
rear=q;
}
void PrintList()
{ Node *p;
p=rear->next;
while (p!=rear)
{cout<<p->next->data<<" ";
p=p->next;}
cout<<endl;
}
int main()
{
int a[]={100,200,300,400,500,600};
LinkList(a,6);
PrintList();
LinkListLDI(788);
PrintList();
LinkListLDI(400);
PrintList();
return 0;
}