| TIP: Click on subject to list as thread! | ANSI |
| echo: | |
|---|---|
| to: | |
| from: | |
| date: | |
| subject: | Sorting Linked Lists |
> PE> One way is to create an array containing pointers to all > PE> your elements in the linked list, and then sort that instead. > PE> I've never tried it myself. > Is there an easy way of initialising this array of pointers > without resorting to any trickery or 'bad code' ?? Sure. Why would you need to use "trickery or 'bad code'" anyway? You can either walk the list once to count the number of elements (and therefore know how large an array of allocate), then walk it again and fill in the array, or you can use realloc() to change the size of the array as required. If your linked list maintains a count of active elements as each one is added or deleted, then this is made even easier and faster. However, if you want to avoid using the secondary array altogether and use some quite nice code to sort linked lists directly using mergesort or quicksort, then locate the C_ECHO snippets file. The one available here is SNIP0493.ZIP, but a new one has been recently released (SNIP9404.ZIP) which I'll probably have on line in a few days. cheers, david ---* Origin: Unique Computing Pty Ltd (3:632/348) SEEN-BY: 50/99 54/54 620/243 623/625 632/103 301 348 386 998 633/371 634/384 SEEN-BY: 635/210 502 503 541 544 636/100 670/206 711/409 430 807 808 809 932 SEEN-BY: 711/934 712/623 713/888 714/906 800/1 @PATH: 632/348 635/503 50/99 54/54 711/808 809 934 |
|
| SOURCE: echomail via fidonet.ozzmosis.com | |
Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.