-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrealloc.cpp
More file actions
92 lines (92 loc) · 2.96 KB
/
realloc.cpp
File metadata and controls
92 lines (92 loc) · 2.96 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
#include"header.h"
int main(){
system("clear");
int *code,n,m,op,svalue;
do{
cout << "\n==============| MENU |=============" <<endl;
cout << "1. Input " << endl;
cout << "2. Output " << endl;
cout << "3. Add " << endl;
cout << "4. Search " << endl;
cout << "5. Update " << endl;
cout << "6. Delete " << endl;
cout << "7. Exit " << endl;
cout << "\nPlease Select One Option : ";
cin >> op;
if(op == 1){
cout << "\nInput Number : "; cin >> n;
code = (int *)calloc(n,sizeof(int *));
cout << endl;
for(int i = 0; i < n; i++){
cout << "Input Value "<< i+1 <<" : ";
cin >> *(code + i);
}
}
if(op == 2){
cout << endl;
for(int i = 0; i < n; i++){
cout << "Output Value "<< i+1 <<" : " << *(code +i) << endl;
}
}
if(op==3){
cout << "\nInput Nnumber To Add : "; cin >> m;
code = (int*)realloc(code,m*sizeof(int*));
cout << endl;
for(int i = n; i < n+m; i++){
cout << "Input Value "<< i+1 <<" : ";
cin >> *(code + i);
}
n = n+m;
}
if(op == 4){
bool b = false;
cout << "\nInput Value To Search : "; cin >> svalue;
for(int i = 0; i < n; i++){
if(svalue == *(code + i)){
cout << "\nOutput Value "<< i+1 <<" : " << *(code+i) << endl ;
b=true;
break;
}
}
if(b==false){
cout << "\nSearch Not Found ..!" << endl;
}
}
if(op == 5){
bool b = false;
cout << "\nInput Value To Search For Update: "; cin >> svalue;
for(int i = 0; i < n; i++){
if(svalue == *(code + i)){
cout << "\nInput Value "<< i+1 <<" : ";
cin >> *(code + i);
cout << endl << "Update is SuccessFully ..!" <<endl;
b=true;
break;
}
}
if(b==false){
cout << "\nSearch Not Found ..!" << endl;
}
}
if(op == 6){
bool b = false;
cout << "\nInput Value To Search For Delete: "; cin >> svalue;
for(int i = 0; i < n; i++){
if(svalue == *(code + i)){
for(int j = i; j < n; j++){
*(code+j) = *(code+j+1);
}
cout << endl << "Delete is SuccessFully ..!" <<endl;
n--;
b=true;
break;
}
}
if(b==false){
cout << "\nSearch Not Found ..!" << endl;
}
}
}while(op != 7);
free(code);
return 0;
}