Home > Back-end >  Joseph ring problem, where is my wrong, always prompt error
Joseph ring problem, where is my wrong, always prompt error

Time:09-16

# include
# include
using namespace std;

Typedef struct {
int a;
} the Book;
Typedef struct LNode {
The Book data.
Struct LNode * next;
} LNode * LinkList;

Void InitList (LinkList & L) {
L=new LNode;
L -> next=L;
}

Void CreateList (LinkList & L, int m) {
LinkList p, r;
R=L;
for(int i=1; i<=m; I++) {
P=new LNode;
P -> data. A=I;
R -> next=p;
P -> next=L -> next;
R=p;
}
}

Void PrintList (LinkList & L, int m, int n) {
LinkList p, q;
P=L;
Int a=1;
for(int i=1; i<=m; I++) {
If (a> m) break;
Else if (I.=n) p=p -> next;
Else if (I==n) {
Cout

next -> data. A <';
Q=p -> next;
P -> next=q -> next;
P=q;
i=0;
+;
}
}
Cout }

Int main () {
Int m, n;
LinkList L;
Do {
Cin>> m> n.
If (m==0 && n==0) break;
InitList (L);
CreateList (L, m);
PrintList (L, m, n);
} the while (true);
return 0;
}

  • Related