Storing a character array within a heap memory

Asked

Viewed 84 times

2

I would like to know how to order a set of characters in a vector, and store them in memory heap.

  • 1

    What have you tried? Show the code you’ve already written and rephrase the question with the specific question/problem you’re facing.

1 answer

1

A vector (dynamic array) at all times will be in heap. You can, with the multiplatform functions of Std C, use malloc, calloc & família (information on link) to dynamically allocate memory. To do vector Sorting, you can use one of the various algorithms of Sort , where each one can have a specific case (better 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 more worthwhile to allocate another block of memory (of the size of the original vector, obviously) and progressively add the ordered data. Thus, you delete the old vector (free space), have the ordered vector (previously allocated space) and save a good job.

Regarding Sort, one of the best algorithms is the Quicksort, although (as already stated) efficient diamonds exist1.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.