| | |
Sorting alphabetically a linked list
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Apr 2009
Posts: 31
Reputation:
Solved Threads: 1
Hi everyone,
I'm dealing with a linked list that is supposed to be sorted. It's consisted of a series of strings which each of these strings are associated with 4 more strings. So, I'm looking for a way to sort this linked list with optimum way possible. I have some ideas myself:
1- Make 5 big array and copy everything into it.
Then sort the first string and make any change that is done to first to the rest of arrays.
2- Do the same algorithm using vectors.
3- Or do the same thing using linked list.
Let's say it's something like this, please bare in mind the numbers are in string format:
3 Tom Hanks 52 male actor
1 Sean Penn 50 male actor
2 Clive Owen 44 male actor
after sorting
1 Sean Penn 50 male actor
2 Clive Owen 44 male actor
3 Tom Hanks 52 male actor
Please let me know what could be the easiest and best way to do it.
I'm dealing with a linked list that is supposed to be sorted. It's consisted of a series of strings which each of these strings are associated with 4 more strings. So, I'm looking for a way to sort this linked list with optimum way possible. I have some ideas myself:
1- Make 5 big array and copy everything into it.
Then sort the first string and make any change that is done to first to the rest of arrays.
2- Do the same algorithm using vectors.
3- Or do the same thing using linked list.
Let's say it's something like this, please bare in mind the numbers are in string format:
3 Tom Hanks 52 male actor
1 Sean Penn 50 male actor
2 Clive Owen 44 male actor
after sorting
1 Sean Penn 50 male actor
2 Clive Owen 44 male actor
3 Tom Hanks 52 male actor
Please let me know what could be the easiest and best way to do it.
http://www.codeguru.com/forum/showthread.php?t=366064
You can use std::sort with a STL container, like a vector or a list. You will need to write a function that determines if a element is greater that an other one.
You can use std::sort with a STL container, like a vector or a list. You will need to write a function that determines if a element is greater that an other one.
![]() |
Similar Threads
- Sorting/Returning a Linked List (C++)
- Implementing a Sorting Algorithm into a Linked List Insert Function (C)
- Problem sorting a simple linked list (C)
- Inserting in a sorted linked list(sorted alphabetically) (C++)
- help by sorting a simply linked list (C)
Other Threads in the C++ Forum
- Previous Thread: Reading input from file
- Next Thread: c++ question
| Thread Tools | Search this Thread |
Tag cloud for C++
api application array arrays based beginner binary bmp c++ c/c++ calculator char char* class classes code compile compiler console conversion convert count data delete deploy dll download dynamic dynamiccharacterarray encryption error file format forms fstream function functions game givemetehcodez graph gui homeworkhelp iamthwee ifstream input int java lib library linker list loop looping loops map math matrix memory microsoft newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference rpg simple sorting string strings struct temperature template templates test text text-file tree url variable vector video visual visualstudio void win32 windows winsock wordfrequency wxwidgets





