3 Replies - 221 Views - Last Post: 09 February 2013 - 09:11 PM Rate Topic: -----

#1 RozenKristal  Icon User is offline

  • D.I.C Regular

Reputation: 45
  • View blog
  • Posts: 315
  • Joined: 29-September 12

Removing elements in linked list

Posted 09 February 2013 - 09:41 AM

So my assignment is removing elements, int type in a linked list, to make them in order of ascending.
So for example:
header -> 2 -> 1 -> 1 -> 4 -> 3 -> 6

I have to traverse the list and remove 1, 1, 3 to get 2 -> 4 -> 6.
I completed the assignment and ran on sample linked lists the professor gave to validate our codes. They correct, but I think if the linked list is longer, my way of doing it would be incorrect.

I just want to ask if you guys know any other ways to do this. Just asking for how... I can do the coding myself. I cant post my code on here since the program is still not yet due, and my classmate could look up the web...

Is This A Good Question/Topic? 0
  • +

Replies To: Removing elements in linked list

#2 Dogstopper  Icon User is offline

  • The Ninjaducky
  • member icon



Reputation: 2870
  • View blog
  • Posts: 11,021
  • Joined: 15-July 08

Re: Removing elements in linked list

Posted 09 February 2013 - 10:23 AM

Ypou can do this both iteratively or recusively, so what you need to do is set the first node's value (if exist) to be min. Then, check every next node's value to see if it is <= to the min. If so, then remove them.
Was This Post Helpful? 0
  • +
  • -

#3 RozenKristal  Icon User is offline

  • D.I.C Regular

Reputation: 45
  • View blog
  • Posts: 315
  • Joined: 29-September 12

Re: Removing elements in linked list

Posted 09 February 2013 - 10:35 AM

But that make min static and stay at first node. For my sample list above, I can easily get 2 -> 4 ->3 -> 6.

But since min == 2, and 4>2, i will keep moving the pter, what happen to 3 then if min stay at 2?

Edit:
Or you think I should increment min by one whenever min < the node next to min?

This is tough, I can only make one method... that all :(

This post has been edited by RozenKristal: 09 February 2013 - 10:44 AM

Was This Post Helpful? 0
  • +
  • -

#4 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8324
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: Removing elements in linked list

Posted 09 February 2013 - 09:11 PM

Quote

But since min == 2, and 4>2, i w

what is the relation about the relational operators == and > with a Linklist and the operations on it ?

Really don't follow your point
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1