i want to sort a linked list in c..
i have understood the algorithm but it seems i am having problems with the code..
i am trying mergesort..any help?
2 replies to this topic
#1
Posted 27 April 2010 - 04:09 AM
|
|
|
#2
Posted 27 April 2010 - 04:59 AM
You should try bubble sort.
Merge sort works best when you have random access.
Merge sort works best when you have random access.
std::string s("oberq zhpu?");std::for_each(s.begin(),s.end(),[&](char&c){c=~c;c=~c-0x01/(~(c|0x20)/0x0D*0x02-0x0B)*0x0D;});std::cout<<s;
#3
Posted 27 April 2010 - 05:32 AM
When sorting lists its best to swap the data in the nodes, not the nodes themselves because its just easier, especially if you put all data in a structure then have the structure in the node. For example
Now in your program when a swap is needed all you have to do is swap the data structures instead of the next and previous pointers.
struct data
{
char last_name[20];
char first_name[20];
char street_address[40];
char city[20];
};
struct node
{
struct node *next;
struct node *previous;
struct data d;
};
Now in your program when a swap is needed all you have to do is swap the data structures instead of the next and previous pointers.
Visit Grandpa's Forums, a social networking forum, with family-oriented arcade games, blogs, discussion forums, and photo albums.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account


Back to top









