File tree Expand file tree Collapse file tree 1 file changed +34
-4
lines changed Expand file tree Collapse file tree 1 file changed +34
-4
lines changed Original file line number Diff line number Diff line change @@ -53,9 +53,40 @@ static void josp_show(joseph *josp)
53
53
printf ("\n" );
54
54
}
55
55
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
+
56
86
int main (int argc , char * * argv )
57
87
{
58
- joseph * josp , * last ;
88
+ joseph * josp ;
89
+ joseph * last ;
59
90
int people , hit ;
60
91
61
92
if (argc < 3 ) {
@@ -69,11 +100,10 @@ int main(int argc, char **argv)
69
100
70
101
josp_init (& josp , people );
71
102
josp_show (josp );
103
+ josp_show (josp );
72
104
73
- #if 0
74
105
last = josp_play (josp , hit );
75
- printf ("last data: %c\n" , last -> data );
76
- #endif
106
+ //printf("last data: %c\n", last->data);
77
107
78
108
return 0 ;
79
109
}
You can’t perform that action at this time.
0 commit comments