From b75b5ac496f687b4dfb4ec24944b771dfc716a6b Mon Sep 17 00:00:00 2001 From: Akash Singh Date: Sat, 17 Oct 2020 20:07:28 +0530 Subject: [PATCH 1/3] #192 shell sort --- Sorting/shell sort.cpp | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 Sorting/shell sort.cpp diff --git a/Sorting/shell sort.cpp b/Sorting/shell sort.cpp new file mode 100644 index 0000000..86f4aa9 --- /dev/null +++ b/Sorting/shell sort.cpp @@ -0,0 +1,42 @@ +#include +using namespace std; +void swap(int &a, int &b) { + int temp; + temp = a; + a = b; + b = temp; +} +void printArray(int *array, int size) { + for(int i = 0; i 0; gap = gap / 2) { + + for(j = gap; j=0; k -= gap) { + if(arr[k+gap] >= arr[k]) + break; + else + swap(arr[k+gap], arr[k]); + } + } + } +} +int main() { + int n; + cout << "Enter the number of elements: "; + cin >> n; + int arr[n]; + cout << "Enter elements:" << endl; + for(int i = 0; i> arr[i]; + } + cout << "Array before Sorting: "; + printArray(arr, n); + shellSort(arr, n); + cout << "Array after Sorting: "; + printArray(arr, n); +} From 0a311146f26d04b0360f94c5ae371da863a54e41 Mon Sep 17 00:00:00 2001 From: AKASH SINGH <52318783+Akashsingh310@users.noreply.github.com> Date: Sun, 18 Oct 2020 10:54:10 +0530 Subject: [PATCH 2/3] Josephus Circle using circular linked list #134 --- josephcircle.cpp | 64 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 josephcircle.cpp diff --git a/josephcircle.cpp b/josephcircle.cpp new file mode 100644 index 0000000..9a618f5 --- /dev/null +++ b/josephcircle.cpp @@ -0,0 +1,64 @@ +#include + +struct circularNode +{ + int data; + circularNode* next; +}; + +circularNode *josephusPosition(); +void showWinner(circularNode*); + +int main() +{ + + showWinner(josephusPosition()); + + return 0; +} + + +circularNode *josephusPosition() +{ + circularNode *temp; + circularNode *head; + + int players; + int number; + + std::cout << "Enter the number of players in game: " << std::endl; + std::cin >> players; + std::cout << "Every xth person gets eliminated- enter x: " << std::endl; + std::cin >> number; + + + head = new circularNode; + temp = head; + temp->data = 1; + for (int i = 2; i <= players; ++i) + { + temp->next = new circularNode; + temp = temp->next; + temp->data = i; + } + + temp->next = head; + + for (int count = players; count > 1; --count) + { + for (int i = 1; i < number; ++i) + temp = temp->next; + + circularNode *q = temp->next; + + temp->next = temp->next->next; + + delete q; + } + return temp; +} + +void showWinner(circularNode* show) +{ + std::cout << "The winner is: " << show->data << std::endl; +} From c63ba54ab2128a0fdb349215e9e1e9b041704fd7 Mon Sep 17 00:00:00 2001 From: AKASH SINGH <52318783+Akashsingh310@users.noreply.github.com> Date: Sun, 18 Oct 2020 12:57:25 +0530 Subject: [PATCH 3/3] Revert "Josephus Circle using circular linked list #134" (#2) --- josephcircle.cpp | 64 ------------------------------------------------ 1 file changed, 64 deletions(-) delete mode 100644 josephcircle.cpp diff --git a/josephcircle.cpp b/josephcircle.cpp deleted file mode 100644 index 9a618f5..0000000 --- a/josephcircle.cpp +++ /dev/null @@ -1,64 +0,0 @@ -#include - -struct circularNode -{ - int data; - circularNode* next; -}; - -circularNode *josephusPosition(); -void showWinner(circularNode*); - -int main() -{ - - showWinner(josephusPosition()); - - return 0; -} - - -circularNode *josephusPosition() -{ - circularNode *temp; - circularNode *head; - - int players; - int number; - - std::cout << "Enter the number of players in game: " << std::endl; - std::cin >> players; - std::cout << "Every xth person gets eliminated- enter x: " << std::endl; - std::cin >> number; - - - head = new circularNode; - temp = head; - temp->data = 1; - for (int i = 2; i <= players; ++i) - { - temp->next = new circularNode; - temp = temp->next; - temp->data = i; - } - - temp->next = head; - - for (int count = players; count > 1; --count) - { - for (int i = 1; i < number; ++i) - temp = temp->next; - - circularNode *q = temp->next; - - temp->next = temp->next->next; - - delete q; - } - return temp; -} - -void showWinner(circularNode* show) -{ - std::cout << "The winner is: " << show->data << std::endl; -}