-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcrack_2_3.c
More file actions
72 lines (65 loc) · 1.04 KB
/
crack_2_3.c
File metadata and controls
72 lines (65 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include <stdio.h>
#include <stdlib.h>
typedef struct list {
int data;
struct list *next;
}list;
list *init(int *, int);
void print(list *);
list *getnode(void);
list *deletenode(list *);
main()
{
int n = 10, position = 3;
int test[] = {3,2,1,3,5,6,2,6,3,1};
list *head = init(test, n);
list *nod = head;
print(head);
for (; position > 0; position--)
nod = nod->next;
nod = deletenode(nod);
if (nod)
print(head);
return 0;
}
list *deletenode(list *nod)
{
if (nod == NULL || nod->next == NULL)
return NULL;
else {
list *temp = nod->next;
nod->data = temp->data;
nod->next = temp->next;
temp = NULL;
return nod;
}
}
list *init(int *test, int n)
{
list *nod, *p, *head;
int m;
for (m = 0; m < n; m++) {
nod = getnode();
nod->data = *test++;
if (m == 0) {
head = p = nod;
continue;
}
p->next = nod;
p = nod;
}
p->next = NULL;
return head;
}
void print(list *head)
{
while (head) {
printf("%d ", head->data);
head = head->next;
}
printf("\n");
}
list *getnode()
{
return (list *)malloc(sizeof(list));
}