#include <stdio.h>
#include <malloc.h>
typedef struct LNode{
int number;
int password;
struct LNode *next;
}linklist;
void insert(linklist *q,int n, linklist *head)
{
int i;
for( i=1; i<n; ++i ){
linklist *p;
p=(linklist*)malloc(sizeof(linklist));
scanf("%d%d",&p->number,&p->password);
q->next=p;
q=p;
}
q->next=head;
}
void Delete(linklist *head,int m)
{
linklist *q,*p;
q=head;
m--;
while(q->next!=q)//判断是否只有一个结点了
{
while( m-1 )//循环到要删除结点的前一个
{
q=q->next;
m--;
}
printf("%d\t",q->next->number);
m=q->next->password;
q->next=q->next->next;
}
printf("%d\n",q->number);
}
void main()
{
linklist *head,*q;
int m,n,i;
printf("The first password is :");
scanf("%d",&m);
printf("The total number is:");
scanf("%d",&n);
if(n>30||n<0)
printf("Error!");
head=(linklist*)malloc(sizeof(linklist));
head->next=NULL;
scanf("%d%d",&head->number,&head->password);
q=head;
insert(q,n,head);//改成在末尾追加插入,你的中间插入顺序就反了
Delete(head,m);
}