-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharray-pointers2
More file actions
157 lines (144 loc) · 2.23 KB
/
array-pointers2
File metadata and controls
157 lines (144 loc) · 2.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
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
//DATA-LAB Assignment01 Bilal khan (p180123)
#include<iostream>
using namespace std;
class List{
public:
int *array=new int[7];
int *current=NULL,*temp=NULL,*head=NULL,*tail=NULL;
int length=0;
List()
{
cout<<"I am frist constructor"<<endl;
head=array;
tail=&array[7];
current=array;
for (int i=0;i<7;i++)
{
*current=0;
current+=1;
length+=1;
//cout<<"current--"<<current<<endl<<endl;
}
current=NULL;
current=array;
}
List(List &L2)
{
cout<<"I am second constructor and working fine"<<endl;
}
void insert()
{
int val=0;
cout<<"value";
cin>>val;
//cout<<"*current"<<current<<endl;
if (length==0)
{
cout<<"List is empty";
*current=val;
return;
}
if (current==tail)
{
cout<<"List is full"<<endl;
return;
}
if (length!=0 && *current==0){
//cout<<"feeding a new value"<<endl;
*current=val;
current+=1;
return;
}
}
void print()
{
cout<<"printing now"<<endl;
for (int i=0;i<7;i++)
{
cout<<array[i]<<endl;
}
}
void remove()
{
int del,flag=0;
current=head;
cout<<"enter value to delete";
cin>>del;
for (int i=0;i<7;i++)
{
if (del==*current && length!=0)
{
cout<<"found"<<endl;
temp=current+1;
*current=0;
swap(*current,*temp);
flag=1;
del=0;
}
current+=1;
}
}
void reinsert(int a,int b)
{
current=head;
int *q=NULL;
q=head;
int check=1;
int size=0,inttemp=0;
for (int i=0;i<7;i++)
{
if (q==NULL || *q==0)
{
cout<<endl<<"SORRY YOU CANNOT INSERT THE VALUE AT:"<<b<<" because some index is empty before"<<endl<<endl;
return;
}
q+=1;
}
for (int i=0;i<7;i++)
{
if (size==b)
{
//cout<<"size==b"<<size<<" "<<b<<endl;
swap(a,*current);
size=*(current+1);
b=*(current+1);
check=0;
//cout<<"size"<<size<<endl;
}
if (check==1)
{
size++;
}
current+=1;
}
}
void clear()
{
cout<<"Clearing everything now"<<endl;
current=head;
for (int i=0;i<7;i++)
{
*current=0;
current+=1;
}
temp=NULL;
head=NULL;
tail=NULL;
}
};
int main()
{
List L;
List L2=L;
L.insert();
L.insert();
L.insert();
L.insert();
L.insert();
L.insert();
L.insert();
L.reinsert(55,2);
L.remove();
L.clear();
L.print();
}