Skip to content

Commit 9125c59

Browse files
committed
约瑟夫问题
完成了约瑟夫问题的编写
1 parent 69cb395 commit 9125c59

File tree

5 files changed

+52
-1
lines changed

5 files changed

+52
-1
lines changed

Josephus/Josephus.layout

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
2+
<CodeBlocks_layout_file>
3+
<ActiveTarget name="Debug" />
4+
<File name="main.c" open="1" top="1" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
5+
<Cursor>
6+
<Cursor1 position="273" topLine="78" />
7+
</Cursor>
8+
</File>
9+
</CodeBlocks_layout_file>

Josephus/bin/Debug/Josephus.exe

419 Bytes
Binary file not shown.

Josephus/main.c

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,56 @@ status initList( LinkList *L )
4444
p = q;
4545
}
4646

47+
q->next = (*L)->next;
48+
4749
return OK;
4850
}
4951

52+
//依次报数,报3的人自杀。
53+
status order4Kill( LinkList *L )
54+
{
55+
int i = 0;
56+
int j = 1;
57+
58+
Node *p, *q;
59+
60+
p = (*L);
61+
62+
while( TRUE )
63+
{
64+
i++;
65+
p = p->next;
66+
67+
if( !p )
68+
return OK;
69+
70+
if( i==2 )
71+
{
72+
q = p->next;
73+
74+
p->next = p->next->next;
75+
p = p->next;
76+
77+
printf("%d,", q->data);
78+
q->next = NULL;
79+
free(q);
80+
81+
if( j%13 == 0 )
82+
printf("\n");
83+
84+
i = 1;
85+
j++;
86+
}
87+
}
88+
}
89+
5090
int main()
5191
{
5292
LinkList list = NULL;
5393

5494
initList(&list);
5595

96+
order4Kill(&list);
97+
5698
return 0;
5799
}

Josephus/obj/Debug/main.o

678 Bytes
Binary file not shown.

loop/loop.layout

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<ActiveTarget name="Debug" />
44
<File name="main.c" open="1" top="1" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
55
<Cursor>
6-
<Cursor1 position="559" topLine="0" />
6+
<Cursor1 position="2743" topLine="163" />
77
</Cursor>
88
</File>
99
</CodeBlocks_layout_file>

0 commit comments

Comments
 (0)