Created
March 29, 2017 14:47
-
-
Save CosminNechifor/b8cf2922c73b88e2204b68585102e235 to your computer and use it in GitHub Desktop.
HeapSort vs QuickSort
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Auto detect text files and perform LF normalization | |
* text=auto | |
# Custom for Visual Studio | |
*.cs diff=csharp | |
# Standard to msysgit | |
*.doc diff=astextplain | |
*.DOC diff=astextplain | |
*.docx diff=astextplain | |
*.DOCX diff=astextplain | |
*.dot diff=astextplain | |
*.DOT diff=astextplain | |
*.pdf diff=astextplain | |
*.PDF diff=astextplain | |
*.rtf diff=astextplain | |
*.RTF diff=astextplain |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<module classpath="CMake" type="CPP_MODULE" version="4" /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<project version="4"> | |
<component name="CMakeWorkspace" PROJECT_DIR="$PROJECT_DIR$" /> | |
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<project version="4"> | |
<component name="ProjectModuleManager"> | |
<modules> | |
<module fileurl="file://$PROJECT_DIR$/.idea/HeapSORTvsQuickSORT.iml" filepath="$PROJECT_DIR$/.idea/HeapSORTvsQuickSORT.iml" /> | |
</modules> | |
</component> | |
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cmake_minimum_required(VERSION 3.6) | |
project(HeapSORTvsQuickSORT) | |
set(CMAKE_CXX_STANDARD 11) | |
set(SOURCE_FILES main.cpp) | |
add_executable(HeapSORTvsQuickSORT ${SOURCE_FILES}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <cstdlib> | |
#include <cstdio> | |
#define MAX 20 | |
void quickSort(int vector[], int left, int right){ | |
int temp, min, max, mid; | |
mid = vector[left + (right - left)/2]; | |
min = left; | |
max = right; | |
do{ | |
while (vector[min] < mid) min++; | |
while (vector[max] > mid) max--; | |
if (min <= max){ | |
temp = vector[min]; | |
vector[min++] = vector[max]; | |
vector[max--] = temp; | |
} | |
}while(min < max); | |
if (left < max) quickSort(vector, left, max); | |
if (right > min) quickSort(vector, min, right); | |
} | |
int main() { | |
int vector[MAX]; | |
for (int i = 0; i < MAX ; ++i) { | |
vector[i] = rand()%(1000) + 1; | |
} | |
printf("\n\nVector inainte de QuickSort:"); | |
for (int k = 0; k < 20; ++k) { | |
printf("%d ", vector[k]); | |
} | |
quickSort(vector, 0, MAX-1); | |
printf("\n\nVector dupa QUICKSORT:"); | |
for (int k = 0; k < 20; ++k) { | |
printf("%d ", vector[k]); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment