From 4eec33dc73d8e284598493eaa1b2a89aed0fb08e Mon Sep 17 00:00:00 2001 From: Arpit61 <45363400+Arpit61@users.noreply.github.com> Date: Fri, 11 Oct 2019 21:10:35 +0530 Subject: [PATCH 1/4] Stack.java This program explains well the push, pop and delete operation --- src/com/ds/Stack data Structure | 78 +++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 src/com/ds/Stack data Structure diff --git a/src/com/ds/Stack data Structure b/src/com/ds/Stack data Structure new file mode 100644 index 0000000..acb9314 --- /dev/null +++ b/src/com/ds/Stack data Structure @@ -0,0 +1,78 @@ +// Java Code for Linked List Implementation + +public class StackAsLinkedList { + + StackNode root; + + static class StackNode { + int data; + StackNode next; + + StackNode(int data) + { + this.data = data; + } + } + + public boolean isEmpty() + { + if (root == null) { + return true; + } + else + return false; + } + + public void push(int data) + { + StackNode newNode = new StackNode(data); + + if (root == null) { + root = newNode; + } + else { + StackNode temp = root; + root = newNode; + newNode.next = temp; + } + System.out.println(data + " pushed to stack"); + } + + public int pop() + { + int popped = Integer.MIN_VALUE; + if (root == null) { + System.out.println("Stack is Empty"); + } + else { + popped = root.data; + root = root.next; + } + return popped; + } + + public int peek() + { + if (root == null) { + System.out.println("Stack is empty"); + return Integer.MIN_VALUE; + } + else { + return root.data; + } + } + + public static void main(String[] args) + { + + StackAsLinkedList sll = new StackAsLinkedList(); + + sll.push(10); + sll.push(20); + sll.push(30); + + System.out.println(sll.pop() + " popped from stack"); + + System.out.println("Top element is " + sll.peek()); + } +} From b198d5b0ff9253578f8c17a1836eacbaacaadca8 Mon Sep 17 00:00:00 2001 From: Arpit61 <45363400+Arpit61@users.noreply.github.com> Date: Sat, 26 Sep 2020 00:21:28 +0530 Subject: [PATCH 2/4] Create bubble sort c++ --- bin/com/sort/bubble sort c++ | 39 ++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 bin/com/sort/bubble sort c++ diff --git a/bin/com/sort/bubble sort c++ b/bin/com/sort/bubble sort c++ new file mode 100644 index 0000000..7677944 --- /dev/null +++ b/bin/com/sort/bubble sort c++ @@ -0,0 +1,39 @@ +#include +using namespace std; + +void swap(int *xp, int *yp) +{ + int temp = *xp; + *xp = *yp; + *yp = temp; +} + +void bubbleSort(int arr[], int n) +{ + int i, j; + for (i = 0; i < n-1; i++) + + + for (j = 0; j < n-i-1; j++) + if (arr[j] > arr[j+1]) + swap(&arr[j], &arr[j+1]); +} + +void printArray(int arr[], int size) +{ + int i; + for (i = 0; i < size; i++) + cout << arr[i] << " "; + cout << endl; +} + +int main() +{ + int arr[] = {64, 34, 25, 12, 22, 11, 90}; + int n = sizeof(arr)/sizeof(arr[0]); + bubbleSort(arr, n); + cout<<"Sorted array: \n"; + printArray(arr, n); + return 0; +} + From 55567002b8181ab84261fe9a656e35066cff0d65 Mon Sep 17 00:00:00 2001 From: Arpit61 <45363400+Arpit61@users.noreply.github.com> Date: Sat, 26 Sep 2020 00:27:12 +0530 Subject: [PATCH 3/4] Delete bubble sort c++ --- bin/com/sort/bubble sort c++ | 39 ------------------------------------ 1 file changed, 39 deletions(-) delete mode 100644 bin/com/sort/bubble sort c++ diff --git a/bin/com/sort/bubble sort c++ b/bin/com/sort/bubble sort c++ deleted file mode 100644 index 7677944..0000000 --- a/bin/com/sort/bubble sort c++ +++ /dev/null @@ -1,39 +0,0 @@ -#include -using namespace std; - -void swap(int *xp, int *yp) -{ - int temp = *xp; - *xp = *yp; - *yp = temp; -} - -void bubbleSort(int arr[], int n) -{ - int i, j; - for (i = 0; i < n-1; i++) - - - for (j = 0; j < n-i-1; j++) - if (arr[j] > arr[j+1]) - swap(&arr[j], &arr[j+1]); -} - -void printArray(int arr[], int size) -{ - int i; - for (i = 0; i < size; i++) - cout << arr[i] << " "; - cout << endl; -} - -int main() -{ - int arr[] = {64, 34, 25, 12, 22, 11, 90}; - int n = sizeof(arr)/sizeof(arr[0]); - bubbleSort(arr, n); - cout<<"Sorted array: \n"; - printArray(arr, n); - return 0; -} - From b13ba15b8459f684f975aaeec8cf97e07d1fe14e Mon Sep 17 00:00:00 2001 From: Arpit61 <45363400+Arpit61@users.noreply.github.com> Date: Sat, 26 Sep 2020 00:28:57 +0530 Subject: [PATCH 4/4] Create bubble sort c++ --- bin/com/sort/bubble sort c++ | 38 ++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 bin/com/sort/bubble sort c++ diff --git a/bin/com/sort/bubble sort c++ b/bin/com/sort/bubble sort c++ new file mode 100644 index 0000000..f6b792a --- /dev/null +++ b/bin/com/sort/bubble sort c++ @@ -0,0 +1,38 @@ +#include +using namespace std; + +void swap(int *xp, int *yp) +{ + int temp = *xp; + *xp = *yp; + *yp = temp; +} + +void bubbleSort(int arr[], int n) +{ + int i, j; + for (i = 0; i < n-1; i++) + + + for (j = 0; j < n-i-1; j++) + if (arr[j] > arr[j+1]) + swap(&arr[j], &arr[j+1]); +} + +void printArray(int arr[], int size) +{ + int i; + for (i = 0; i < size; i++) + cout << arr[i] << " "; + cout << endl; +} + +int main() +{ + int arr[] = {64, 34, 25, 12, 22, 11, 90}; + int n = sizeof(arr)/sizeof(arr[0]); + bubbleSort(arr, n); + cout<<"Sorted array: \n"; + printArray(arr, n); + return 0; +}