Storing a vector of characters within a heap memory

2

I would like to know how to sort a character set into a vector, and store it in the heap memory.

    
asked by anonymous 24.04.2015 / 18:43

1 answer

1

A vector (dynamic array) always will be in the heap. You can, using the cross-platform std C functions, use malloc, calloc & família (information on the link) to dynamically allocate memory. To do vector sorting, you can use one of multiple sort algorithms , where each can have a specific case and worse) and you must decide which one suits you best (large amount of information / less amount of information). It is important to note that during the sorting process, it is often worth it to allocate another block of memory (of the original vector size, obviously) and progressively add the ordered data. So you delete the old vector (free space), have the vector ordered (space previously allocated) and save a good job.

Regarding sort, one of the best algorithms is Quicksort , although ( as already mentioned) there are efficient weights 1 .

    
24.04.2015 / 23:34