-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathList.cpp
97 lines (88 loc) · 1.54 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#include <iostream>
using namespace std;
const int size = 10;
template<class t>
class list {
t entry [size];
int count ;
public :
list (){
count = 0;
}
bool empty (){
return count==0;
}
int Size (){
return count;
}
bool full ()
{
return count==size-1;
}
bool insert (int pos,t item){
if ((pos<0) || (pos>count))return 0;
if (full())return 0;
for (int i=count-1 ; i>=pos ; i--){
entry[i+1] = entry [i];
}
entry[pos] = item;
count++;
return 1;
}
bool replace (int pos ,t item){
if ((pos<0) || (pos>=count))return 0;
if (empty())return 0;
entry [pos] = item;
count++;
return 1;
}
bool remove (int pos){
if (empty())return 0;
if ((pos<0) || (pos>=count))return 0;
for (int i=pos ; i<count-1 ; i++){
entry[i] = entry [i+1];
}
count--;
return 1;
}
void operator = (list <int> test){
int countOrg = count;
for (int i=0 ; i<countOrg ; i++)
{remove(0);}
countOrg = test.Size();
t data;
for (int i=0 ; i<countOrg ; i++){
test.get(i , data);
insert (i , data);
}
}
bool get (int pos,t &item){
if (empty())return 0;
if ((pos<0) || (pos>=count))return 0;
item = entry[pos];
return 1;
}
void print (){
for (int i=0; i<count ;i++){
cout << entry[i] << " | ";
}
cout<<endl;
}
};
int main(int argc, char *argv[])
{
list <int> ll ,l2;
l2.insert(0 , 70);
ll.insert(0 , 10);
l2.insert(1 , 20);
ll.insert(1 , 40);
ll.insert(0 , 56);
ll.print();
l2.print();
l2=ll;
cout<<"==========="<<endl;
ll.print();
//ll.remove(2);
l2.print();
return 0;
}