-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlist.cpp
74 lines (70 loc) · 1.36 KB
/
list.cpp
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
/*************************************************************************
> File Name: list.cpp
> Author: Royecode
> Mail: [email protected]
> Created Time: 2015年10月25日 星期日 13时30分42秒
************************************************************************/
#include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;
struct node
{
int val;
struct node *next;
};
void show(node *head)
{
for(node *p = head -> next; p != head; p = p -> next)
cout << p -> val << " ";
cout << endl;
}
int main(int argc, char **argv)
{
node *head, *p;
head = p = new node;
srand(time(NULL));
int n = 10;
for(int i = 0; i < n; ++i)
{
node *q = new node;
q -> val = rand() % 100;
q -> next = NULL;
//if(p == NULL)
// p = q;
//else
//{
p -> next = q;
p = p -> next;
//}
//cout << q -> val << " ";
}
//cout << endl;
p -> next = head;
show(head);
for(p = head -> next; head -> next != NULL; p = p -> next)
{
if(p == head)
{
if(p -> next == head) head -> next = NULL;
continue;
}
p -> val -= 10;
//cout << p -> val << endl;
show(head);
if(p -> val < 0)
{
node *q;
for(q = p -> next; q -> next != p; q = q -> next)
{
;//cout << "+++";//if(q = head)
}
//cout << "!!" << endl;
node *temp = p;
q -> next = p -> next;
p = q -> next;
delete temp;
}
}
return 0;
}