Created
April 11, 2012 13:24
-
-
Save dhruvbird/2359271 to your computer and use it in GitHub Desktop.
Comparing merge sort implementations for doubly linked lists
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
/* Compiling: Create a file named list_sort.c in the src/ folder and | |
* run: | |
* | |
* gcc list_sort.c lcthw/list.o lcthw/list_algos.o -I . -O2 | |
* | |
* Time: 14.025s | |
* | |
*/ | |
#include "lcthw/list.h" | |
#include "lcthw/list_algos.h" | |
int | |
int_cmp(void *lhs, void *rhs) { | |
return (int)lhs - (int)rhs; | |
} | |
int | |
main() { | |
List *l = List_create(); | |
int i; | |
for (i = 0; i < 5000000; ++i) { | |
List_push(l, (void*)i); | |
} | |
List_merge_sort(l, int_cmp); | |
return 0; | |
} |
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
/* Compiling: Create a file named list_sort.cpp in the src/ folder and | |
* run: | |
* | |
* g++ list_sort.cpp -o a.out.cpp -O2 | |
* | |
* Time: 0.647s | |
* | |
*/ | |
#include <list> | |
#include <iostream> | |
using namespace std; | |
int | |
main() { | |
list<int> *pl = new list<int>; | |
list<int> &l = *pl; | |
int i; | |
for (i = 0; i < 5000000; ++i) { | |
l.push_back(i); | |
} | |
l.sort(); | |
// Add cout to prevent compiler from optimizing everything out. | |
cout<<"smallest element: "<<l.front()<<endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment