Sorting

Radix Sort

Download Radix Sort // //  main.cpp //  Radix_Sort // //  Created by Zhenlin Pei on 12/24/18. //  Copyright © 2018 Zhenlin Pei. All rights reserved. // // C++ implementation of Radix Sort #include<iostream> using namespace std; // A utility function to get maximum value in arr[] int getMax(int arr[], int n) {     int… read more »

Bucket Sort

Download Bucket Sort // //  main.cpp //  Bucket_Sort // //  Created by Zhenlin Pei on 12/24/18. //  Copyright © 2018 Zhenlin Pei. All rights reserved. // // C++ program to sort an array using bucket sort #include <iostream> #include <algorithm> #include <vector> using namespace std; // Function to sort arr[] of size n using bucket… read more »

Counting Sort

Download Counting Sort // //  main.cpp //  Counting_Sort // //  Created by Zhenlin Pei on 12/24/18. //  Copyright © 2018 Zhenlin Pei. All rights reserved. // // C Program for counting sort #include <stdio.h> #include <string.h> #define RANGE 255 // The main function that sort the given string arr[] in // alphabatical order void countSort(char… read more »

Heap Sort

Geeks for Geeks for Heap Sort. Visualization for Heap Sort. Animation for Heap Sort.   Download Heap Sort   // //  main.cpp //  Heap_Sort // //  Created by Zhenlin Pei on 12/24/18. //  Copyright © 2018 Zhenlin Pei. All rights reserved. // // C++ program for implementation of Heap Sort #include <iostream> using namespace std;… read more »

Quick Sort

Download Quick Sort // //  main.cpp //  Quick_Sort // //  Created by Zhenlin Pei on 12/24/18. //  Copyright © 2018 Zhenlin Pei. All rights reserved. // /* C implementation QuickSort */ #include<stdio.h> // A utility function to swap two elements void swap(int* a, int* b) {     int t = *a;     *a… read more »

Merge Sort

Download Merge Sort // //  main.cpp //  Merge_Sort // //  Created by Zhenlin Pei on 12/23/18. //  Copyright © 2018 Zhenlin Pei. All rights reserved. // /* C program for Merge Sort */ #include<stdlib.h> #include<stdio.h> // Merges two subarrays of arr[]. // First subarray is arr[l..m] // Second subarray is arr[m+1..r] void merge(int arr[], int… read more »

Shell Sort

Download Shell Sort // //  main.cpp //  Shell_Sort // //  Created by Zhenlin Pei on 12/23/18. //  Copyright © 2018 Zhenlin Pei. All rights reserved. // // C++ implementation of Shell Sort #include <iostream> using namespace std; /* function to sort arr using shellSort */ int shellSort(int arr[], int n) {     // Start… read more »

Insertion Sort

Download Insertion Sort // //  main.cpp //  Insertion_Sort // //  Created by Zhenlin Pei on 12/23/18. //  Copyright © 2018 Zhenlin Pei. All rights reserved. // // C program for insertion sort #include <stdio.h> #include <math.h> /* Function to sort an array using insertion sort*/ void insertionSort(int arr[], int n) {     int i,… read more »

Selection Sort

Download Selection_Sort // //  main.cpp //  Selection_Sort // //  Created by Zhenlin Pei on 12/23/18. //  Copyright © 2018 Zhenlin Pei. All rights reserved. // // C program for implementation of selection sort #include <stdio.h> void swap(int *xp, int *yp) {     int temp = *xp;     *xp = *yp;     *yp… read more »

Bubble Sort

Download Bubble_Sort Last login: Sun Dec 23 13:26:10 on ttys000 Zhenlins-MacBook-Pro:~ pei$ cd CPP/Sorting/ Zhenlins-MacBook-Pro:Sorting pei$ ls Bubble_Sort Zhenlins-MacBook-Pro:Sorting pei$ cd Bubble_Sort/ Zhenlins-MacBook-Pro:Bubble_Sort pei$ vim Bubble_Sort.cpp // Optimized implementation of Bubble sort  #include <stdio.h>  void swap(int *xp, int *yp)  {  int temp = *xp;  *xp = *yp;  *yp = temp;  }  // An optimized version… read more »

Sidebar