-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathalgorithm.cc
More file actions
102 lines (73 loc) · 1.23 KB
/
Copy pathalgorithm.cc
File metadata and controls
102 lines (73 loc) · 1.23 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#include "algorithm.h"
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
char*
strrev2(char* src)
{
assert(src != NULL);
//char c;
for(int i = 0, j = strlen(src) - 1; i < j ; i++, j--)
{
//c = src[i];
//src[i] = src[j];
//src[j] = c;
src[i] ^= src[j];
src[j] ^= src[i];
src[i] ^= src[j];
}
return src;
}
void
List_Init(PListItem* list, unsigned int number)
{
PListItem head, p = *list;
head = p;
p = new ListItem;
*list = p;
p->data = 0;
p->next = NULL;
for(unsigned int i = 1; i < number ; i++)
{
p->next = new ListItem;
p->next->data = i;
p->next->next = NULL;
p = p->next;
}
for(unsigned int i = 1; i <= number ; i++)
{
}
}
void
List_Print(PListItem list)
{
PListItem p = list;
while(p)
{
printf("List: %d\n", p->data);
p = p->next ? p->next : NULL;
}
}
PListItem*
List_Rev(PListItem* list)
{
PListItem c, n, old_head, nn;
c = *list;
old_head = *list;
n = (*list)->next ? (*list)->next : NULL;
nn = (*list)->next->next ? (*list)->next->next : NULL;
if (n == NULL)
return list;
while(nn)
{
n->next = c;
c = n;
n = nn;
nn = nn->next;
}
n->next = c;
*list = n;
old_head->next = NULL;
return list;
}