-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathClass_List1.h
138 lines (117 loc) · 2.39 KB
/
Class_List1.h
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
struct List1 {
int Info;
struct List1 *Next;
};
class List_One { protected:
struct List1 *Start;
int Amount;
static int counter;
int ID = 0;
public:
List_One(void);
List_One(int N);
List_One(int N,int Diapazon,int Shift);
~List_One();
void Print(void);
void Append(int N);
void Insert(int N,int Before);
void Erase(int Out);
void Replace(int N1,int N2);
int GetValue(int N);
int Empty(void);
int ListLength(void);
struct List1 *GetAddress(int N);
};
int List_One::counter = 0;
List_One::List_One(void)
{
ID = counter;
printf("Default List_One %d\n",ID);
Start= new struct List1;
Start->Next=NULL;
Amount=0;
counter++;
}
List_One::List_One(int N,int Diapazon,int Shift)
{
ID = counter;
printf("Random made List_One %d !!!\n",ID);
Start= new struct List1;
Start->Next=NULL;
Amount=0;
srand(time(NULL));
for(int Count=0;Count<N;Count++){
Append(rand()%Diapazon-Shift);
}
counter++;
}
int List_One::Empty(void)
{
if(Amount) return 0;
return 1;
}
int List_One::ListLength(void)
{return Amount;
}
struct List1 * List_One::GetAddress(int N)
{struct List1 *tmp;
int Count;
if(N<0||N>ListLength())return NULL;
tmp=Start;
for(Count=0;Count<N;Count++)tmp=tmp->Next;
return tmp;
}
void List_One::Append(int N)
{
struct List1 *Fresh,*Last;
Fresh=new (struct List1);
Last=GetAddress(ListLength());
Last->Next=Fresh;Fresh->Next=NULL;
Fresh->Info=N;Amount++;
}
void List_One::Insert(int N,int Before)
{
struct List1 *Last,*Fresh;
Fresh=new(struct List1);
Last=GetAddress(Before-1);
Fresh->Next=Last->Next;Last->Next=Fresh;
Fresh->Info=N;Amount++;
}
void List_One::Erase(int Out)
{
struct List1 *Before,*Erased;
Before=GetAddress(Out-1);
Erased=Before->Next;
Before->Next=Erased->Next;
delete (Erased);
Amount--;
}
int List_One::GetValue(int N)
{
struct List1 *tmp;
tmp=GetAddress(N);
return tmp->Info;
}
void List_One::Print(void)
{
int Count;
struct List1 *tmp;
if(Empty()){
printf("List %d is EMPTY!!!\n",ID); return;}
for(Count=1;Count<=Amount;Count++)
{
tmp=GetAddress(Count);
printf("%d->%x ",tmp->Info,tmp->Next);
}
printf("\n");
}
List_One::~List_One()
{
printf("Destructor List_One %d\n", ID);
counter--;
while(!Empty())Erase(1);
delete Start;
}