8000 joseph: 目前运行出错,怀疑是joseph_play返回栈数据引起 · home-coder/data-abstraction-001@6eb40f3 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6eb40f3

Browse files
author
oneface
committed
joseph: 目前运行出错,怀疑是joseph_play返回栈数据引起
1 parent ddd74a6 commit 6eb40f3

File tree

1 file changed

+34
-4
lines changed

1 file changed

+34
-4
lines changed

002-joseph.c

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,40 @@ static void josp_show(joseph *josp)
5353
printf("\n");
5454
}
5555

56+
static joseph *josp_play(joseph *josp, int hit)
57+
{
58+
int i;
59+
joseph *pjs = josp;
60+
if (!pjs) {
61+
printf("josp is not exsit\n");
62+
return NULL;
63+
}
64+
65+
/* 首先确定第一个报数人的前趋结点 cur [双链表处理好一些,此处以单链表为例] */
66+
do {
67+
pjs = pjs->next;
68+
}while(pjs->next != josp);
69+
70+
joseph *fnode;
71+
do {
72+
for (i = 1; i < hit; i++) {
73+
pjs = pjs->next;
74+
}
75+
fnode = pjs->next;
76+
pjs->next= pjs->next->next;
77+
//free(fnode);
78+
fnode = NULL;
79+
pjs = pjs->next;
80+
}while(pjs != josp);
81+
82+
printf("pjs->data %c\n", pjs->data);
83+
return pjs;
84+
}
85+
5686
int main(int argc, char **argv)
5787
{
58-
joseph *josp, *last;
88+
joseph *josp;
89+
joseph *last;
5990
int people, hit;
6091

6192
if (argc < 3) {
@@ -69,11 +100,10 @@ int main(int argc, char **argv)
69100

70101
josp_init(&josp, people);
71102
josp_show(josp);
103+
josp_show(josp);
72104

73-
#if 0
74105
last = josp_play(josp, hit);
75-
printf("last data: %c\n", last->data);
76-
#endif
106+
//printf("last data: %c\n", last->data);
77107

78108
return 0;
79109
}

0 commit comments

Comments
 (0)
0