GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 11-Dec-2006, 00:44
shinx shinx is offline
New Member
 
Join Date: Nov 2006
Posts: 2
shinx is on a distinguished road

Help quick sort template


Implement QuickSort to sort singly linked list. The function will return the head of the sorted list:

CPP / C++ / C Code:
template<typename T>

struct NODE

{

    T data;

    NODE *next;

}

template<typename T>

NODE<T>* QuickSortList( NODE<T>* list )

{

   

}

i think
1. it should implement it as recursive function to simplify the code.
2. it has to use pivot to connect left and right sub lists. To make it work, it’ll need to append pivot to the end of left sub list, and make sure after sorted the list still keeps pivot at the end of the list in the case of multiple items that have the same value as pivot.

we know that
Quick sort works in following steps:

1. Pick an item from unsorted collection.
2. Split the collection such that all items with value less than pivot go to left set, and all items with value greater or equal to pivot values go to right set.
3. Sort left set and right set.
4. Connect left set, pivot and right set to form sorted collection: left set + pivot + right set.
Last edited by LuciWiz : 11-Dec-2006 at 02:37. Reason: Please insert your C/C++ code between [cpp] & [/cpp] tags
  #2  
Old 11-Dec-2006, 14:00
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 5,309
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold

Re: help quick sort template


Quote:
Originally Posted by shinx
Implement QuickSort to sort singly linked list


Most of the time just posting an assignment and saying something like, "I don't know how to do it," will not get a helpful response. The idea is that you use what you learned in class or in some previous class to start the program. If (when) you get to a part that doesn't work the way you expect or if you write and test part of the code but are stuck for ideas about how to proceed, then.

1. Post the code that you have so far.

2. Ask specific questions about parts that you don't understand.

Like this: "When I tried to compile the program, the compiler gave the following message(s) that I didn't understand: ...

or

Like this: "The program compiled without any warning or error messages, but then I gave the program the following input:... I expected the following output:..., but the program (crashed) (gave the following wrong output..) (whatever...)"



Regards,

Dave

Footnote: since the assignment involves sorting a linked list of NODE objects, you also have to implement (and populate) such a thing before you can sort it. If you already know how to do that, good, but if you are going to post any code for sorting a list, you should also show the code that gets values into the list (and show what you expect the output to be before and after the sort routine.)
 
 

Recent GIDBlogVista ?Widgets? on Windows XP by LocalTech

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Fatal error C1083: Cannot open include file mia C++ Forum 5 14-May-2007 15:35
Testing a template class earachefl C++ Forum 7 13-May-2006 17:21
Combining Vectors and References Frankg C++ Forum 7 14-Jan-2006 06:17
Quick, Insertion, and Partition silicon C++ Forum 0 18-May-2005 20:49
Merge and Heap...which is really faster silicon C++ Forum 0 10-May-2005 13:46

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 17:56.


vBulletin, Copyright © 2000 - 2010, Jelsoft Enterprises Ltd.