#include <iostream>
#include <stdlib.h>
using namespace std;
typedef struct node
{
int num;
struct node* next;
}NODE,*PNODE;
PNODE creat_(int n)//建立循环双向链表
{
int num_;
PNODE head,p,q;
head=(PNODE)malloc(sizeof(NODE));
if(head==NULL)
{
cout<<"fault";
}
cin>>num_;
head->num=num_;
head->next=NULL;
q=head;
n=n-1;
while(n--)
{
p=(PNODE)malloc(sizeof(NODE));
cin>>num_;
p->num=num_;
q->next=p;
q=p;
}
q->next=NULL;
return head;
}
void traverse(PNODE head)
{
PNODE q=head;
while(q!=NULL)
{
cout<<q->num<<' ';
q=q->next;
}
}
void insert(PNODE head,int i,int e)
{
PNODE q=head;
PNODE new_;
int j=1;
for(j=1;j<(i-1);j++)//从第一个到i的前一个数字
{
q=q->next;
}
new_=(PNODE)malloc(sizeof(NODE));
new_->num=e;
new_->next=q->next;
q->next=new_;
}
void delet(PNODE head,int i)
{
PNODE q=head;
PNODE temp;
int j=1;
for(j=1;j<(i-1);j++)
{
q=q->next;
}
temp=q->next;
q->next=temp->next;
free(temp);
}
int main()
{
PNODE head;
head=creat_(7);
delet(head,5);
//insert(head,4,0);
traverse(head);
}