8000 joseph: malloc 的用法居然也会出现思维过不去的时候,卡住了 · home-coder/data-abstraction-001@ab866e8 · GitHub
[go: up one dir, main page]

Skip to content

Commit ab866e8

Browse files
author
oneface
committed
joseph: malloc 的用法居然也会出现思维过不去的时候,卡住了
1 parent 7000993 commit ab866e8

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

002-joseph.c

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#include <stdio.h>
2+
#include <stdlib.h>
3+
#include <string.h>
4+
#include <errno.h>
5+
6+
/****************002-joseph.c***********************
7+
8+
使用没有头节点但是要有首元节点的链式存储结构来解决此问题,因为方便删除元素
9+
***************************************************/
10+
11+
typedef struct _joseph {
12+
char data; //a b c d e f
13+
struct _joseph *next;
14+
}joseph;
15+
16+
static void josp_init(joseph **josp, int people)
17+
{
18+
while (people--) { //malloc ?
19+
}
20+
}
21+
22+
int main(int argc, char **argv)
23+
{
24+
joseph *josp;
25+
int people, hit;
26+
27+
if (argc < 3) {
28+
fprintf(stderr, "Please read usage: ./a.out 24 5 error: %s: \n", strerror(errno));
29+
exit(-1);
30+
}
31+
32+
people = atoi(argv[1]);
33+
hit = atoi(argv[2]);
34+
printf("p %d h %d\n", people, hit);
35+
36+
josp_init(&josp, people);
37+
38+
return 0;
39+
}

0 commit comments

Comments
 (0)
0