-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path代码.txt
69 lines (59 loc) · 924 Bytes
/
代码.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include<stdio.h>
#include<stdlib.h>
#include <iostream>
using namespace std;
typedef struct
{
int num;
int key;
}ElemType;
typedef struct LNode
{
ElemType data;
struct LNode *next;
}LNode, *LinkList;
LinkList CreateListFromTail (int n)
{
LinkList h,s,p;
int i;
h=(LNode*)malloc(sizeof(LNode));
h->next=NULL;
h->data.num=1;
cin>>h->data.key;
p=h;
for(i=2;i<=n;i++)
{
s=(LNode*)malloc(sizeof(LNode));
cin>>s->data.key;
s->data.num=i;
p->next=s;
p=s;
}
p->next=h;
return h;
}
void del(LinkList h,int n,int m)
{
int i,j; LinkList p,q;
p=h;
for(i=1;i<=n;i++)
{
for(j=1;j<=m-1;j++)
{q=p;
p=p->next;}
q->next=p->next;
cout<<p->data.num<<endl;
m=p->data.key;
free(p);
p=q->next;
}
}
int main( )
{ LinkList h;int n,m;
cout<<"ÊäÈë³õʼÈËÊýºÍM"<<endl;
cin>>n>>m;
h=CreateListFromTail(n);
del(h,n,m);
system("PAUSE");
return 0;
}