Sorting a bucket using pointers and two arrays of structures

I am working on a phone book application where I want to sort the nodes representing each entry according to the name of the client. I want to use a ladle sorting algorithm where I have two arrays of related list structures.

The trick is that I don't want to use deletion and construction to move nodes through buckets.

Is there an easier way using pointers? Moving pointers through buckets can be a lot easier, but I don't know how to implement it. I do this in C, but help in any other language is appreciated.

I appreciate your help.

+4
source share
1 answer

It depends on how the records are stored. If you save each entry in a cell in a linked list, you can sort them in the form of a bucket with a constant amount of memory by simply moving items from the original list and into buckets. This will require you to use pointers and recode pointers, but it is not as complicated as it seems. You simply spliced โ€‹โ€‹cells from the main list and into buckets for sorting.

One question is, is there a reason why you want to use bucket sort to sort names? You can sort the rows using basket sort, but for this you will almost certainly need more than two buckets; you will probably have one for each letter of the alphabet, and one for "there are no letters." If you have a linked list, you might consider exploring merge sorting as a possibility, as it is not too difficult to implement and has excellent run-time guarantees.

+2
source

Source: https://habr.com/ru/post/1339277/


All Articles