Skip to content

Instantly share code, notes, and snippets.

@CosminNechifor
Created March 29, 2017 14:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CosminNechifor/b8cf2922c73b88e2204b68585102e235 to your computer and use it in GitHub Desktop.
Save CosminNechifor/b8cf2922c73b88e2204b68585102e235 to your computer and use it in GitHub Desktop.
HeapSort vs QuickSort
# 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
<?xml version="1.0" encoding="UTF-8"?>
<module classpath="CMake" type="CPP_MODULE" version="4" />
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CMakeWorkspace" PROJECT_DIR="$PROJECT_DIR$" />
</project>
<?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>
cmake_minimum_required(VERSION 3.6)
project(HeapSORTvsQuickSORT)
set(CMAKE_CXX_STANDARD 11)
set(SOURCE_FILES main.cpp)
add_executable(HeapSORTvsQuickSORT ${SOURCE_FILES})
#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