diff --git a/StackArray.cpp b/StackArray.cpp new file mode 100644 index 000000000..21f5c6ae5 --- /dev/null +++ b/StackArray.cpp @@ -0,0 +1,185 @@ +#include +using namespace std; + +struct list +{ + int data[50]; + int top=0; + bool isSorted=false; + + int BinarySearch(int *array, int first, int last, int x) + { + if(lastarray[mid]) + return (BinarySearch(array, mid+1, last, x)); + } + + int LinarSearch(int *array, int x) + { + for (int i = 0; i < top; i++) + { + if (array[i]==x) + { + return i; + } + } + + return -1; + } + + int Search(int x) + { + int pos=-1; + + if (isSorted) + { + pos=BinarySearch(data, 0, top-1, x); + } + + else + { + pos=LinarSearch(data, x); + } + + if (pos!=-1) + { + cout<<"\nElement found at position : "< pos; i--) + { + data[i]=data[i-1]; + } + top++; + data[pos]=x; + } + } + + void Remove(int x) + { + int pos=Search(x); + cout<<"\n"<>choice; + switch (choice) + { + case 1: cout<<"\nEnter the element to be inserted : "; + cin>>x; + L.insert(x); + break; + case 2: cout<<"\nEnter the element to be removed : "; + cin>>x; + L.Remove(x); + break; + case 3: cout<<"\nEnter the element to be searched : "; + cin>>x; + L.Search(x); + break; + case 4: L.Sort(); + break; + case 5: L.Show(); + break; + } + } + while(choice!=0); + return 0; +}