Switch to full style
C++ code examples
Post a reply

Library Sort

Thu Nov 13, 2008 3:06 pm

Library of sorting:
cpp code
#include <iostream>
#include <algorithm>

using namespace std;

/*
* This program reads in integers and sorts them using the library sort
* function. The algorithm header provides the sorting function.
*
* Author: Tom Bennet
*/

const int MAX_NUM_INTS = 100;
int main()
{
int ints[MAX_NUM_INTS]; // Where the numbers go.

// Read them in.
int i;
for(i = 0; i < MAX_NUM_INTS && cin >> ints[i]; ++i);
int numints = i;

// Sort them. The library sort algorithm wants a pointer to the
// the start of the data, and a pointer one past the end.
sort(ints, ints + numints);

// Print them.
cout << "==================" << endl;
for(int i = 0; i < numints; ++i)
cout << ints[i] << endl;
cout << "==================" << endl;
}




Re: Library Sort

Wed Jan 18, 2012 3:23 pm

where is library sort implementation

Re: Library Sort

Sun Jan 27, 2013 9:15 pm

cpp code
#include <stdlib.h>
#include <string.h>

#include "sort.h"



int issort(void *data, int size, int esize, int (*compare)(const void *key1,
const void *key2)) {

char *a = data;

void *key;

int i,
j;


if ((key = (char *)malloc(esize)) == NULL)
return -1;



for (j = 1; j < size; j++) {

memcpy(key, &a[j * esize], esize);
i = j - 1;



while (i >= 0 && compare(&a[i * esize], key) > 0) {

memcpy(&a[(i + 1) * esize], &a[i * esize], esize);
i--;

}

memcpy(&a[(i + 1) * esize], key, esize);

}



free(key);

return 0;

}

There also a list of sorting :
c-c/insertion-sort-c-t73.html
c-c/c-recursion-sort-t664.html
c-c/c-bubble-sort-t983.html

Post a reply
  Related Posts  to : Library Sort
 Image I/O library     -  
 Math Function Library     -  
 PHP SOAP server returns array using NuSOAP Library     -  
 PHP SOAP server returns array using NuSOAP Library     -  
 Java Library Database Management System Project     -  
 simple Ajax library solving back button and bookmarks     -  
 C++ Bubble Sort     -  
 sort words in c++     -  
 Sort a list     -  
 Array sort     -  

Topic Tags

C++ Sorting