|
-
March 26th, 2012, 12:39 PM
#6
Re: Linked List Problem
 Originally Posted by monarch_dodra
Does your assignment require that you modify your input list "in place"? Wouldn't it be simpler to create a second "result" list, that you would fill as you process the input?
Also, IMO, the "pairs" thing is just designed to confuse you. Why don't you just create a list with all the unique digits, and then "double them" once you have them all?
Code:
input: 5 5 5 5 2 3 1 3 3 2 3 0 2 4 1 4
output1: 5 2 3 1 0 4
output2: 5 5 2 2 3 3 1 1 0 0 4 4
The algorithm is pretty simple:
Code:
For every item in input: Is it inside output?
Yes - Process next item
No - Place inside output
One of the requirements is that I have to detach and insert the first found duplicate. Of course if these nodes are adjacent then all I must do is delete subsequent duplicates. But I am only allowed to use ONE list.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|