![]() |
|
#1
|
|||
|
|||
C++ HelpHey there,
I know you guys cant help when it comes to homework, so im kind of stuck. I need to make a c++ program that will sort a doubly linked like in decsending order and im not sure where to start. So maybe if someone could even just write a simple algorithm to give me a guide line?? or something like that, it would be very much appreciated. Thank you |
|
#2
|
|||
|
|||
Re: C++ HelpQuote:
A doubly linked list containing what data type? Your sort algorithm is largely dependent on the data type stored in the list. Basically, you just implement the necessary features of the list for basic list management. Then, you enable your sort routine using iteration and list management functions. :davis: |
|
#3
|
|||
|
|||
Re: C++ HelpThe data type would be integers....
|
|
#4
|
|||
|
|||
Algorithm helpHey guys this what ive done for an algorithm to sort in descending order a doubly linked list. Dont know if its right completly, so if anyone can please point out anything they think is wrong
Thank You BEGIN sortDoubleLink (PList, POne) SET min to integer SET array [1…n] IF (PList not null) SET min to PList -> data SET POne to PList -> Link WHILE (POne not null) IF (POne < next data) SET POne to PList SET PList -> Link ELSE INCREMENT to next array ENDWHILE ENDIF RETURN (list) END sortDoubleLink Last edited by LuciWiz : 02-May-2006 at 07:35.
Reason: [Merged thread]
|
|
#5
|
|||
|
|||
Re: C++ HelpQuote:
search google for probably 1 of these bubblesort, quicksort, mergesort algorithm. When you say doubly linked list do you mean like a binary tree or a linear double linked list with current pointing to next and previous? [leftlink][data][rightlink] - > [leftlink][data][rightlink] - > [leftlink][data][rightlink] or ________________[leftlink][data][rightlink] _______________ /___________________\ [leftlink][data][rightlink]________________[leftlink][data][rightlink] excuse my attempt at drawing? |
|
#6
|
|||
|
|||
Algorithm 2Here is another algorithm that needs checking
here is the question: Please write a non-recursive algorithm in pseudo code to solve the above problem using stacks. The algorithm receives the following parameters: a two-dimensional array maze (indexed from [1, 1]) that represents the maze, an integer N, where N > 0, which is the size of the maze (hence, the array has valid elements from maze[1, 1] to maze[N, N]), two integers (m1, m2) that are the coordinates of the starting point of the mouse (e.g., (m1=2, m2=1) means the starting point is row 2, column 1), and two integers (e1, e2) that are the coordinates of the exist. For example, to represent the following figure (where the shaded cells represent the wall), we have maze[1, 1] = 1, maze[1, 2] = 1, maze[1, 3] = 1, maze[2, 1] = 0, maze[2, 2] = 1, maze[2, 3] = 0, maze[3, 1] = 0, maze[3, 2] = 0, maze[3, 3] = 0; m1=2, m2=1, e1=2, e2=3. here is the algorithm i have written BEGIN mouseMaze SET starting point (m1=2, m2=1) SET exit (e1=2, e2=3) WHILE (mouse = starting point) move mouse (m1=1, m2=1) THEN move mouse (m1=1, m2=2) & (m1=1, m2=3) THEN exit maze if exit found IF not exit PRINT “(1, 1), (1, 2), (1, 3), (2, 3)” ELSE RETURN to start point ENDIF ENDWHILE WHILE (mouse = starting point) move mouse (m1=2, m2=2) THEN exit maze if exit found IF maze empty PRINT “(2, 2), (2, 3) ELSE RETURN to start point ENDIF ENDWHILE WHILE (mouse = starting point) move mouse (m1=3, m2=1) THEN move mouse (m1=3, m2=2) & (m1=3, m2=3) THEN exit maze IF not exit PRINT “(3, 1), (3, 2), (3, 3), (2, 3)” ELSE RETURN to start point ENDIF ENDWHILE END mouseMaze Last edited by LuciWiz : 02-May-2006 at 07:45.
Reason: [Merged thread]
|
|
#7
|
|||
|
|||
Re: C++ Helpi mean linear double linked list with current pointing to next and previous. Ive attempted a algorithm in the new post a few posts above this, dont know if its right tho...
|
|
#8
|
||||
|
||||
Re: C++ HelpQuote:
I have merged that thread with this one - you will find it as post #4 in this thread. Please don't double post on the same problem. It makes it difficult for the people offering help to do so, as I think you might find happened in this case (since they couldn't see the algorithm you came up with). A more suggestive thread name would be helpful too. I ask you to please try and read the "Guidelines for posting requests for help" (the link is in my signature), in order to help us help you. I wish you happy learning. Best regards, Lucian __________________
Please read these Guidelines before posting on the forum "A person who never made a mistake never tried anything new." Einstein |
|
#9
|
||||
|
||||
Re: C++ HelpI have merged the new thread you started too... please post the next related issue in the same thread.
I am not sure how the software used for merging threads works (it porbably orders posts by date), but this post was merged as post #6 in this thread. __________________
Please read these Guidelines before posting on the forum "A person who never made a mistake never tried anything new." Einstein |
Recent GIDBlog
First week of IA training by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The