-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathprog3.cpp
63 lines (53 loc) · 959 Bytes
/
prog3.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
//Prog. for array deletion
#include<iostream>
using namespace std;
void arraytraverse(int,int,int[],int);
void arraydel(int,int,int[],int,int);
int main(){
int list[5],lb,ub,pos;
//Input array
cout<<"Enter elements of array";
for(int i=0;i<=4;i++){
cin>>list[i];
}
cout<<"Enter LB and UB";
cin>>lb>>ub;
cout<<"Enter POS to del";
cin>>pos;
//Function call
cout<<"Before Array";
arraytraverse(lb,ub,list,5);
arraydel(lb,ub,list,1,5);
}
void arraytraverse(int lb,int ub,int list[],int max){
if(ub>max){
cout<<"Error";
return;
}
if(lb>ub){
cout<<"Error";
return;
}
for(int i=lb;i<=ub;i++){
cout<<"\t"<<list[i];
}
}
void arraydel(int lb,int ub, int list[], int pos, int max){
if(lb>ub){
cout<<"Bound error";
return;
}
if(ub>max){
cout<<"max error";
return;
}
if(pos<lb){
cout<<"error";
return;
}
for(int i=pos-1;i<=ub;i++){
list[i]=list[i+1];
}
cout<<"\n"<<"After";
arraytraverse(lb,ub,list,5);
}