| | |
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 |
api array beginner binary bitmap c++ c/c++ calculator char char* class classes coding compile compiler console conversion count data database delete desktop developer directshow dll download dynamic email encryption error file forms fstream function functions game getline google graph gui homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference return rpg sorting string strings struct template templates test text text-file tree unix url vector video visualstudio win32 windows winsock word wordfrequency wxwidgets





