From 5cfa13271daece830222e50884d60170bcdf69bb Mon Sep 17 00:00:00 2001 From: Tripti mishra <48507731+triptimishra99@users.noreply.github.com> Date: Thu, 1 Oct 2020 18:19:11 +0530 Subject: [PATCH 1/5] Update array_rev.c --- codes/arrays/array_rev.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/codes/arrays/array_rev.c b/codes/arrays/array_rev.c index a2c15fc..833f02d 100644 --- a/codes/arrays/array_rev.c +++ b/codes/arrays/array_rev.c @@ -9,7 +9,8 @@ int main(){ { scanf("%d",&arr[i]); } - printf("Reversed Array is\n"); + for(int loop = n-1; loop >= 0; loop--) + printf("%d ", arr[loop]); return 0; -} \ No newline at end of file +} From 695897f1a9cdbb34a35c4e0d307982294bf0bdc4 Mon Sep 17 00:00:00 2001 From: Tripti mishra <48507731+triptimishra99@users.noreply.github.com> Date: Thu, 1 Oct 2020 18:31:19 +0530 Subject: [PATCH 2/5] Update sum_n_number.c No need for the above line --- codes/recurssion/sum_n_number.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/codes/recurssion/sum_n_number.c b/codes/recurssion/sum_n_number.c index ba9e240..976a7d2 100644 --- a/codes/recurssion/sum_n_number.c +++ b/codes/recurssion/sum_n_number.c @@ -3,7 +3,7 @@ int main() { int n; - int sum_natural(int ); + //int sum_natural(int ); printf("n = "); scanf("%d",&n); printf("Sum of first %d natural numbers = %d\n",n,sum_natural(n)); @@ -16,4 +16,4 @@ int sum_natural(int n) { return n + sum_natural(n-1); } -} \ No newline at end of file +} From 7bdaa3b6331f5a684e39293770c508eb07afca4c Mon Sep 17 00:00:00 2001 From: Ujjwal Puri Date: Mon, 22 Jan 2024 22:50:00 +0545 Subject: [PATCH 3/5] edit --- codes/stack/stack_implement_cpp.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 codes/stack/stack_implement_cpp.cpp diff --git a/codes/stack/stack_implement_cpp.cpp b/codes/stack/stack_implement_cpp.cpp new file mode 100644 index 0000000..e674289 --- /dev/null +++ b/codes/stack/stack_implement_cpp.cpp @@ -0,0 +1,12 @@ +#include +using namespace std; + +//implementation of stack using a class +class stack{ + public: + int top; + int *arr; + int size; + + void +} \ No newline at end of file From a72c610c3d10be809a2d78e07b94bd90650c588f Mon Sep 17 00:00:00 2001 From: Ujjwal Puri Date: Mon, 22 Jan 2024 22:56:09 +0545 Subject: [PATCH 4/5] implementation of stack with class --- codes/stack/stack_implement_cpp.cpp | 73 +++++++++++++++++++++++++++-- 1 file changed, 70 insertions(+), 3 deletions(-) diff --git a/codes/stack/stack_implement_cpp.cpp b/codes/stack/stack_implement_cpp.cpp index e674289..5dd28ca 100644 --- a/codes/stack/stack_implement_cpp.cpp +++ b/codes/stack/stack_implement_cpp.cpp @@ -2,11 +2,78 @@ using namespace std; //implementation of stack using a class -class stack{ +class Stack{ + //properties public: int top; - int *arr; + int *arr; int size; - void +//constructor to dynamically allocate the array size + Stack(int size){ + this->size=size; + arr=new int[size]; + top=-1; + } + void push ( int element){ + if(size-top>1){ + top++; + arr[top]=element; + } + else{ + cout<<"stack overflow"; + } + } + void pop(){ + if(top>=0){ + top--; + } + else{ + cout<<"stack underflow"<=0 && top44 + + st.pop(); + cout<<"Top is "<43 + //another pop + st.pop(); + cout<<"Top is "< Date: Tue, 23 Jan 2024 23:06:33 +0545 Subject: [PATCH 5/5] implemented queue --- codes/queue/queue_implement.c | 83 +++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 codes/queue/queue_implement.c diff --git a/codes/queue/queue_implement.c b/codes/queue/queue_implement.c new file mode 100644 index 0000000..5f7452b --- /dev/null +++ b/codes/queue/queue_implement.c @@ -0,0 +1,83 @@ +#include +# define SIZE 100 +//prototype +void enqueue(); +void dequeue(); +void show(); +int arr[SIZE]; +int Rear = - 1; +int Front = - 1; +int main() +{ + int ch; + while (1) + { + printf("1.Enqueue Operation\n"); + printf("2.Dequeue Operation\n"); + printf("3.Display the Queue\n"); + printf("4.Exit\n"); + printf("Enter your choice of operations : "); + scanf("%d", &ch); + switch (ch) + { + case 1: + enqueue(); + break; + case 2: + dequeue(); + break; + case 3: + show(); + break; + case 4: + exit(0); + default: + printf("Incorrect choice \n"); + } + } +} + +void enqueue() +{ + int insert_item; + if (Rear == SIZE - 1) + printf("Overflow \n"); + else + { + if (Front == - 1) + + Front = 0; + printf("Element to be inserted in the Queue\n : "); + scanf("%d", &insert_item); + Rear = Rear + 1; + arr[Rear] = insert_item; + } +} + +void dequeue() +{ + if (Front == - 1 || Front > Rear) + { + printf("Underflow \n"); + return ; + } + else + { + printf("Element deleted from the Queue: %d\n", arr[Front]); + Front = Front + 1; + } +} + +void show() +{ + + if (Front == - 1) + printf("Empty Queue \n"); + else + { + printf("Queue: \n"); + for (int i = Front; i <= Rear; i++) + printf("%d ", arr[i]); + printf("\n"); + } +} \ No newline at end of file