From 44a8b47ebc4a888b7a35466275c0b391e68011a9 Mon Sep 17 00:00:00 2001 From: Kshitij-10 Date: Mon, 5 Oct 2020 17:12:35 +0530 Subject: [PATCH 1/2] Corrected Linear Search --- search-with-noob/linear_search.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/search-with-noob/linear_search.cpp b/search-with-noob/linear_search.cpp index 8806cd8..d3180db 100644 --- a/search-with-noob/linear_search.cpp +++ b/search-with-noob/linear_search.cpp @@ -18,12 +18,18 @@ int main() int search_element; //Take the input of the element to be searched by the user. + cout<<"Enter the search element"<>search_element; int result = linear_search(arr,size,search_element); //If the result is -1 then print that the element is not present in the array. //If the result is any value but -1 then print the element is found on that index. + if(result==-1) + cout<<"Element not found"< Date: Fri, 9 Oct 2020 14:40:38 +0530 Subject: [PATCH 2/2] added stack using array --- datastructure-with-noob/stack_array.c | 78 +++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 datastructure-with-noob/stack_array.c diff --git a/datastructure-with-noob/stack_array.c b/datastructure-with-noob/stack_array.c new file mode 100644 index 0000000..774e9f7 --- /dev/null +++ b/datastructure-with-noob/stack_array.c @@ -0,0 +1,78 @@ +#include + +#define n 5 +int stack[n]; +int top=-1; +void push() +{ + int x; + if(top==n-1) + { + printf("Overflow\n"); + + } + printf("enter data\n"); + scanf("%d",&x); + top=top+1; + stack[top]=x; +} + +void pop() +{ + int x; + if(top==-1) + { + printf("Underflow\n"); + } + x=stack[top]; + printf("The popped element is %d\n",x); + top=top-1; +} + +void peek() +{ +int x; +x=stack[top]; +printf("THe top most element is %d\n",x); +} + +void display() +{ + int i; + printf("abc\n"); + for(i=top;i>=0;i--) + { + printf("%d ",stack[i]); + } + printf("\n"); +} +int main() +{ +int ch; +do +{ printf("1 for Push \n2 for pop \n3 for peek \n4 for display \n0 for exit\n"); + + printf("enter the choice\n"); + scanf("%d",&ch); + switch(ch) + { + case 1: + push(); + break; + case 2: + pop(); + break; + case 3: + peek(); + break; + case 4: + display(); + break; + default: + printf("Invalid Choice\n"); + break; + } +}while(ch!=0); + return 0; +} +