-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharray-pointers1
More file actions
152 lines (126 loc) · 1.82 KB
/
array-pointers1
File metadata and controls
152 lines (126 loc) · 1.82 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
//Assignment01 datastructures
#include<iostream>
using namespace std;
class Pointer
{
int *current=NULL,*head=NULL,*tail=NULL,*temp=NULL;
int *array=new int[5];
int length1=0;
public:
Pointer()
{
head=array;
current=head;
tail=head;
}
void add()
{
int input;
if (head==current)
{
for (int i=0;i<5;i++){
cin>>input;
*current=input;
current=current+1;
length1+=1;
tail+=1;
}
}
current -= 1;
tail -= 1;
}
void get()
{
cout<<" i am get function,i will tell where *current pointer* is pointing ";
cout<< *current<<endl;
}
void length()
{
int count=1;
int *tempq=NULL;
tempq=array;
while(*tempq!=*tail)
{
tempq+=1;
count++;
}
cout<<"Total length is: "<<count<<endl;
}
void update()
{
int new_number,position;
cout<<"What is the new number? ";
cin>>new_number;
*current=new_number;
for (int i=0;i<5;i++)
{
cout<<array[i];
}
}
void back()
{
current=current-1;
cout<<"Current Pointer moved back: "<<*current<<endl;
}
void next()
{
current=current+1;
cout<<"Pointer moved one value forward: "<<*current<<endl;
}
void start()
{
current=head;
cout<<"head:"<<*current<<endl;
}
void end()
{
current=tail;
cout<<"tail:"<<*current<<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 && length1 !=0)
{
//cout<<"found"<<endl;
temp=current+1;
*current=0;
swap(*current,*temp);
flag=1;
del=0;
}
current+=1;
}
}
void print()
{
int *q=NULL;
q=array;
for (int i=0;i<5;i++)
{
cout<<"printing"<<*q<<endl;
q+=1;
}
}
};
int main()
{
Pointer alpha;
alpha.add();
alpha.get();
alpha.length();
alpha.update();
cout<<endl<<"showing after update"<<endl;
alpha.print();
alpha.back();
alpha.next();
alpha.start();
alpha.end();
alpha.remove();
alpha.print();
}