There is no such thing as innocence, only degrees of guilt | Flickr!
zoek eens bubblesort, mergesort, insertion sort of quicksort
uit MSDN
goed genoeg??void qsort( void *base, size_t num, size_t width, int (__cdecl *compare )(const void *elem1, const void *elem2 ) );
Parameters
base
Start of target array
num
Array size in elements
width
Element size in bytes
compare
Comparison function
elem1
Pointer to the key for the search
elem2
Pointer to the array element to be compared with the key
Remarks
The qsort function implements a quick-sort algorithm to sort an array of num elements, each of width bytes. The argument base is a pointer to the base of the array to be sorted. qsort overwrites this array with the sorted elements. The argument compare is a pointer to a user-supplied routine that compares two array elements and returns a value specifying their relationship. qsort calls the compare routine one or more times during the sort, passing pointers to two array elements on each call:
compare( (void * D elem1, (void * D elem2 );
The routine must compare the elements, then return one of the following values:
Return Value Description
< 0 elem1 less than elem2
0 elem1 equivalent to elem2
> 0 elem1 greater than elem2
The array is sorted in increasing order, as defined by the comparison function. To sort an array in decreasing order, reverse the sense of greater than and less than in the comparison function.
"There are three stages in scientific discovery: first, people deny that it is true; then they deny that it is important; finally they credit the wrong person."
het is wel geen array waar ze in staan maar gewoon losOp zondag 18 november 2001 13:14 schreef drZymo het volgende:
uit MSDN
[..]
goed genoeg??
maar ik zal eens wat proberen
There is no such thing as innocence, only degrees of guilt | Flickr!
Verwijderd
Ik krijg het idee dat je 26 integers hebt gedeclareerd. Da's nie zo'n goed idee. Je moet een array (zoek maar op) van integers declareren, dan kun je de sorteer algoritmes gebruiken die hierboven staan.
k ga ik gelijk doenOp zondag 18 november 2001 13:16 schreef Xalista het volgende:
Ik krijg het idee dat je 26 integers hebt gedeclareerd. Da's nie zo'n goed idee. Je moet een array (zoek maar op) van integers declareren, dan kun je de sorteer algoritmes gebruiken die hierboven staan.
There is no such thing as innocence, only degrees of guilt | Flickr!
Nee.Op zondag 18 november 2001 13:14 schreef drZymo het volgende:
uit MSDN
[..]
goed genoeg??
Is C, geen C++.
C++ heeft gewoon std::sort, hoef je niet zulke
ingewikkelde dingen te vertellen.
Bovendien weet je nog niet wat voor datastructuur
hij gebruikt; leuk dat je weet dat de meest voorkomende
letter 80 keer voorkomt, maar welke is dat?
Maar in C++ kun je een zelfsorterende datastructuur
gebruiken: std::map / std::multimap.
Key waarop je moet sorteren is frequentie( int ),
symbol is char, en keys kunnen vaker voorkomen.
( 2 letters met zelfde frequentie ) ->
std::multimap< int, char > tabel;
tabel.insert( std::make_pair (
aantal_as, 'a' ) );
// kweenie waar je de aantallen bewaart
Hoogste aantal is nu tabel.end()->first, bijbehorende
karakter is tabel.end()->second. Eennahoogste is
tabel.end()-1 etc.
Man hopes. Genius creates. Ralph Waldo Emerson
Never worry about theory as long as the machinery does what it's supposed to do. R. A. Heinlein
Verwijderd
Mooi, iemand anders merkt het onvermijdbare opOp maandag 19 november 2001 14:04 schreef MSalters het volgende:
Nee.
Is C, geen C++.
C++ heeft gewoon std::sort, hoef je niet zulke
ingewikkelde dingen te vertellen.
BOEM! segmentation dinges en zo. Je bedoelt natuurlijk tabel.back().first. tabel.end() is een past-end iterator (een voorbij het laatste element).Hoogste aantal is nu tabel.end()->first, bijbehorende
karakter is tabel.end()->second. Eennahoogste is
tabel.end()-1 etc.
Pagina: 1