Skip to content

Commit 6920db1

Browse files
committed
changes made to main file
1 parent 79eb43a commit 6920db1

File tree

3 files changed

+52
-17
lines changed

3 files changed

+52
-17
lines changed

.vscode/settings.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
"C_Cpp.errorSquiggles": "Disabled",
3232
"files.associations": {
3333
"string": "cpp",
34-
"iostream": "cpp"
34+
"iostream": "cpp",
35+
"ostream": "cpp"
3536
}
3637
}

index/index.cpp

+50-16
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ class Program{
77
public:
88
int numberOfElements, key;
99
int elements[0];
10-
void main(){
10+
int firstDecision, secondDecision;
11+
void header(){
1112
cout<<"\n\t\t*****************************************************************************"<<endl;
1213
cout<<"\n\t\t\t\t\tSEARCHING AND SORTING ALGORITHMS"<<endl;
1314
cout<<"\n\t\t*****************************************************************************"<<endl;
@@ -17,8 +18,33 @@ class Program{
1718
void welcomeMessage(){
1819
cout<<"The Algorithms available in this Program are:"<<endl;
1920
cout<<"Searching Algorithms"<<endl;
20-
cout<<"1. Linear Search"<<endl;
21-
cout<<"2. Binary Search"<<endl<<endl; Sleep(3000);
21+
cout<<"Sorting Algorithms"<<endl;
22+
cout<<endl;
23+
24+
cout<<"Do you want to proceed with Sorting or Searching Algorithm?"<<endl;
25+
cout<<"Enter 0 for Sorting or 1 for Searching Algorithm.......";
26+
cin>>firstDecision;
27+
cout<<endl;
28+
29+
while(firstDecision < 0 or firstDecision > 2){
30+
if(firstDecision == 0){
31+
cout<<"Searching Algorithms"<<endl;
32+
cout<<"1 Linear Search"<<endl;
33+
cout<<"2 Binary Search"<<endl<<endl; Sleep(3000);
34+
}
35+
else if(firstDecision == 1){
36+
cout<<"Sorting Algorithms"<<endl;
37+
cout<<"Sorting Algorithms"<<endl;
38+
cout<<"1. Selection Sort"<<endl;
39+
cout<<"2. Insertion Sort"<<endl;
40+
cout<<"3. Nearly Sorted"<<endl;
41+
cout<<"4. Shell Sort"<<endl;
42+
cout<<"5. Quick Sort"<<endl;
43+
cout<<"6. Merge Sort"<<endl;
44+
cout<<"7. Radix Sort"<<endl<<endl; Sleep(10000);
45+
}
46+
}
47+
2248
cout<<"Sorting Algorithms"<<endl;
2349
cout<<"1. Selection Sort"<<endl;
2450
cout<<"2. Insertion Sort"<<endl;
@@ -27,8 +53,6 @@ class Program{
2753
cout<<"5. Quick Sort"<<endl;
2854
cout<<"6. Merge Sort"<<endl;
2955
cout<<"7. Radix Sort"<<endl<<endl; Sleep(10000);
30-
cout<<"Do you want to proceed with Sorting or Searching Algorithm?"<<endl;
31-
cout<<"Enter 0 for Sorting or 1 for Searching Algorithm."<<endl;
3256
}
3357

3458
void takeInput(){
@@ -141,6 +165,7 @@ class Algorithms : public Program{
141165
takeInput();
142166
cout<<"UNSORTED";
143167
displayInput();
168+
144169
}
145170

146171
//Shell sort
@@ -172,15 +197,16 @@ class Algorithms : public Program{
172197
int partition(int elements[], int lowIndex, int highIndex){
173198
// takeInput();
174199
// cout<<"UNSORTED";
200+
// int elements[];
175201
// displayInput();
176202
int temp;
177203
// cout<<"Select a low index for partition ";cin>>lowIndex;
178204
// cout<<"Select a high index for partition ";cin>>highIndex;
179205
int midpoint = lowIndex + (highIndex - lowIndex) / 2;
180-
int pivot = elements[midpoint];
206+
int pivot = elements[midpoint]; // 4 is pivot
181207
bool done = false;
182208
while(!done){
183-
while(elements[lowIndex] < pivot){
209+
while(elements[lowIndex] < pivot){ // array = [10, 2, 78, 4, 45, 32, 7, 11]
184210
lowIndex += 1;
185211
}
186212
while(pivot < elements[highIndex]){
@@ -198,10 +224,12 @@ class Algorithms : public Program{
198224
highIndex -= 1;
199225
}
200226
}
227+
201228
return highIndex;
229+
202230
}
203231

204-
void quickSort(int elements[], int lowIndex, int highIndex){
232+
void quickSort(int lowIndex, int highIndex){
205233
if(lowIndex >= highIndex){
206234
return;
207235
}
@@ -229,16 +257,22 @@ class Algorithms : public Program{
229257
// };
230258

231259
int main(){
260+
261+
int numberOfElements;
262+
int elements[0];
263+
cout<<"Enter the number of elements in the Array to be processed >>>>>> ";
264+
cin>>numberOfElements;
265+
for(int i=0; i<numberOfElements; i++){
266+
cout<<"Element at index "<<i<<" ";
267+
cin>>elements[i];
268+
}
232269
Algorithms m;
233-
// m.project();
234-
// m.welcomeMessage();
270+
m.header();
271+
//m.welcomeMessage();
235272
// m.partition();
236-
int elements[8] = {10, 2, 78, 4, 45, 32, 7, 11};
237-
m.quickSort(elements, 0, 8-1);
238-
cout<<"\nSORTED [ ";
239-
for(int i=0; i < 8; i++){
240-
cout<<elements[i]<<" ";
241-
}cout<<"]";
273+
// m.binarySearch();
274+
m.quickSort(elements,0,5);
275+
242276

243277
return 0;
244278
};

index/index.exe

1.64 KB
Binary file not shown.

0 commit comments

Comments
 (0)