From bb927bf6477b0d3858ee480f0c587cac63998e0f Mon Sep 17 00:00:00 2001 From: Hashini Senanayake <76748283+HashiniSenanayake@users.noreply.github.com> Date: Mon, 18 Oct 2021 18:05:52 +0530 Subject: [PATCH 1/4] Insertion_Sort.cpp Added "the" in front of number in line 41 --- Insertion_Sort.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Insertion_Sort.cpp b/Insertion_Sort.cpp index bf8c6ed..769a5f7 100644 --- a/Insertion_Sort.cpp +++ b/Insertion_Sort.cpp @@ -38,7 +38,7 @@ void insertionSort(int arr[], int n) { int main() { int n; - cout<<"Enter number of elements : "; + cout<<"Enter the number of elements : "; cin>>n; int arr[n]; From 9cecedcc084b01c81126d5d3dd6767cc5c8bdfc6 Mon Sep 17 00:00:00 2001 From: PratikPrakhar <84954224+PratikPrakhar@users.noreply.github.com> Date: Tue, 19 Oct 2021 19:06:29 +0530 Subject: [PATCH 2/4] Added program of Stack using linked list --- Stack using linked list.c | 106 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 Stack using linked list.c diff --git a/Stack using linked list.c b/Stack using linked list.c new file mode 100644 index 0000000..c3f9864 --- /dev/null +++ b/Stack using linked list.c @@ -0,0 +1,106 @@ +#include +#include + +struct Node +{ + int data; + struct Node *next; +}; + +struct Node *head = NULL; + +void push(int value) +{ + struct Node *n = (struct Node *)malloc(sizeof(struct Node *)); + if (head == NULL) + { + head = n; + n->data = value; + n->next = NULL; + return; + } + + n->next = head; + n->data = value; + head = n; +} + +void pop() +{ + struct Node *temp = head; + if (head == NULL) + { + printf("\nStack is empty.\n"); + return; + } + + head = head->next; + temp->next = NULL; +} + +void peek() +{ + if (head == NULL) + { + printf("\nStack is empty.\n"); + return; + } + + printf("The top element is: %d\n", head->data); +} + +void display() +{ + struct Node *temp = head; + if (head == NULL) + { + printf("\nStack is empty.\n"); + return; + } + printf("\nElements of stack are:\n"); + while (temp != NULL) + { + printf("%d\n", temp->data); + temp = temp->next; + } +} + +int main() +{ + while (1) + { + printf("\n=======Menu=======\n"); + printf("1. Push\n"); + printf("2. Pop\n"); + printf("3. Peek\n"); + printf("4. Display\n"); + printf("5. Exit\n\n"); + int c, n; + scanf("%d", &c); + switch (c) + { + case 1: + printf("Enter the element to be inserted: "); + scanf("%d", &n); + push(n); + break; + case 2: + pop(); + break; + case 3: + peek(); + break; + case 4: + display(); + break; + case 5: + exit(0); + break; + + default: + printf("Please select a valid option."); + } + } + + return 0; +} \ No newline at end of file From 5d70b380e3b37522b4fbe31fffcf76307afa1c86 Mon Sep 17 00:00:00 2001 From: VikasArsul <92970538+VikasArsul@users.noreply.github.com> Date: Fri, 22 Oct 2021 11:28:25 +0530 Subject: [PATCH 3/4] Solution for Rat-In-Maze problem in C++ --- rat_in_maze.cpp | 75 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 rat_in_maze.cpp diff --git a/rat_in_maze.cpp b/rat_in_maze.cpp new file mode 100644 index 0000000..808a791 --- /dev/null +++ b/rat_in_maze.cpp @@ -0,0 +1,75 @@ +#include +using namespace std; + +bool isSafe(int** arr, int x, int y, int n){ + + if( x>n; + + int** arr = new int*[n]; + for(int i=0; i>arr[i][j]; + } + } + + int** solArr = new int*[n]; + for(int i=0; i Date: Sat, 23 Oct 2021 09:48:38 +0530 Subject: [PATCH 4/4] Create Kadanes_Algo --- Kadanes_Algo | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 Kadanes_Algo diff --git a/Kadanes_Algo b/Kadanes_Algo new file mode 100644 index 0000000..d788079 --- /dev/null +++ b/Kadanes_Algo @@ -0,0 +1,20 @@ +#include +using namespace std; +int main() +{ + int n; + cin >> n; + int ms = 0, cs = 0; + int arr[n]; + for (int i = 0; i < n; i++) + { + cin >> arr[i]; + cs += arr[i]; + if (cs < 0) + cs = 0; + else if (cs >= ms) + ms = cs; + } + cout << ms << endl; + return 0; +}