Home arrow static arrow Java Programming [Archive] - Reversing LinkedList elements
Warning: Creating default object from empty value in /www/htdocs/w008deb8/wiki/components/com_staticxt/staticxt.php on line 51
Java Programming [Archive] - Reversing LinkedList elements
This topic has 142 replies on 10 pages.    « Previous | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | Next »

Posts:8,813
Registered: 10/4/00
Re: Reversing LinkedList elements  
Aug 8, 2004 2:12 PM (reply 90 of 142)



 
1. Draw a picure of the train I described above.

2. Put the tip of your pencil on the engine/caboose. Draw an 'X'

3. Move your pencil to the next car behind

4. If there is another car behind without an 'X' go to step 3

5. Post your answer
 

Posts:24,036
Registered: 2/3/03
Re: Reversing LinkedList elements  
Aug 8, 2004 2:19 PM (reply 91 of 142)



 
A lot of Americans suffer from recurring bouts of
enlightened self interest or persistent
self-righteousness. They seem to be immune to any
compulsion to examine an issue objectively.

I hereby challenge anyone's claim of objectivity. There ain't no such animal.
 

Posts:8,813
Registered: 10/4/00
Re: Reversing LinkedList elements  
Aug 8, 2004 2:20 PM (reply 92 of 142)



 
I hereby challenge anyone's claim of
objectivity. There ain't no such animal.

Agreed. But the compulsion may exist.

In theory anyway...
 

Posts:18,384
Registered: 21.03.00
Re: Reversing LinkedList elements  
Aug 8, 2004 2:22 PM (reply 93 of 142)



 
Think for a moment. Where will the first item be
when
you have reversed the list??

Lets see ... heres what i thought

Link previous = first ; all the links (elements) wentinto previousLink current  = first.next; // all other links wentinto current except  FIRST (element which is 1) first.next = null ; //NOW we DON"T need this thinganymore therefore null... 

Correct?

Why do you make it so complicated? Don't look at the code.. just THINK. The first element will be last. And there will not be an element after it, so next should point to null. Was that hard?

/Kaj

 

Posts:24,036
Registered: 2/3/03
Re: Reversing LinkedList elements  
Aug 8, 2004 2:25 PM (reply 94 of 142)



 
I hereby challenge anyone's claim of
objectivity. There ain't no such animal.

Agreed. But the compulsion may exist.

In theory anyway...

:o)

I've given up trying to be "objective" when I realized the fultility of that exercise. Nowadays, it's more important for me to understand the framework and context of the inevitable bias that comes with personal experience. I can appreciate reasonableness where objectivity may be lacking. :o)
 

Posts:37,103
Registered: 3/30/99
Re: Reversing LinkedList elements  
Aug 8, 2004 2:26 PM (reply 95 of 142)



 
A lot of Americans suffer from recurring bouts of
enlightened self interest or persistent
self-righteousness. They seem to be immune to any
compulsion to examine an issue objectively.

I hereby challenge anyone's claim of
objectivity. There ain't no such animal.

True, but I think the point that the beautiful, sexy, delectable bbritta was making (by the way, bbritta, thanks for those pictures you sent me of yourself--yum!) is that, even aside from the unattainability of pure objectivity, many people don't even try--they just assume that what they want/think/feel must be "right" and must be the same for everybody. I doubt it's limited to just us Yanks though.
 

Posts:24,036
Registered: 2/3/03
Re: Reversing LinkedList elements  
Aug 8, 2004 2:28 PM (reply 96 of 142)



 
I think a better exercise would be the following in understanding a doubly-linked list and how to reverse it:

1) Draw a picture of a killer whale (orcinus orca).
2) Right behind the orca, draw another.
3) Now draw a small omnibus somewhere on the same page.
4) Turn the page over and mark it with a large "K".
5) Turn the page back over and write "airplane" three times.
6) Think about a waterfall.

Do that, and you should have a pretty good idea.
 

Posts:357
Registered: 8/5/04
Re: Reversing LinkedList elements  
Aug 8, 2004 2:29 PM (reply 97 of 142)



 
wouldn't have putting this two shitty ******* together made things a ******* LOT SIMPLER?

Why a GAP of ******* LOOP in between these two statements ? ??
        first.next = null ;        first = previous;
 

Posts:24,036
Registered: 2/3/03
Re: Reversing LinkedList elements  
Aug 8, 2004 2:29 PM (reply 98 of 142)



 
even aside from the unattainability of pure objectivity, many people don't
even try--they just assume that what they
want/think/feel must be "right" and must be the same
for everybody.

That's where "reasonableness" comes in. Of course, that's "reasonableness" as defined by me. ;o)

I doubt it's limited to just us Yanks though.

Hear hear.
 

Posts:24,036
Registered: 2/3/03
Re: Reversing LinkedList elements  
Aug 8, 2004 2:31 PM (reply 99 of 142)



 
wouldn't have putting this two shitty *******
together made things a ******* LOT SIMPLER?

Why a GAP of ******* LOOP in between these two
statements ? ??

There, I've helped with your F-bombs. **** censors.

Okay, that said - the gap exists because you probably didn't draw the killer whales close enough together. Try again, but this time, make sure the one's nose is right by the other's tail.
 

Posts:357
Registered: 8/5/04
Re: Reversing LinkedList elements  
Aug 8, 2004 2:34 PM (reply 100 of 142)



 
that ******* ******* took hell lot of my ******* time
 

Posts:37,103
Registered: 3/30/99
Re: Reversing LinkedList elements  
Aug 8, 2004 2:37 PM (reply 101 of 142)



 
even aside from the unattainability of pure
objectivity, many people don't
even try--they just assume that what they
want/think/feel must be "right" and must be the same
for everybody.

That's where "reasonableness" comes in.

Yes, I saw your "reasonableness" comment, and I agree. Unfortunately, reasonableness is almost as hard to come by as objectivity sometimes.

Of course,
that's "reasonableness" as defined by me. ;o)

That's fine, to the extent that it intersects with the one true definition--mine, naturally. Stray outside that, and you'll find yourself smote. :-)

 

Posts:24,036
Registered: 2/3/03
Re: Reversing LinkedList elements  
Aug 8, 2004 2:38 PM (reply 102 of 142)



 
that ******* ******* took hell lot of my
******* time

Excellent job with the F-Bombs. Now you can use them with impunity, along with "OP".

I assume you've got it all figured out now, so I'm glad to hear the orca diagram helped out.
 

Posts:24,036
Registered: 2/3/03
Re: Reversing LinkedList elements  
Aug 8, 2004 2:39 PM (reply 103 of 142)



 
That's where "reasonableness" comes in.

Yes, I saw your "reasonableness" comment, and I agree.
Unfortunately, reasonableness is almost as hard to
come by as objectivity sometimes.

Definitely. If I were to assign relative importance to the two, though, the prize would go to the former. It's at least "more possible" (?) to attain than the latter.

Of course,
that's "reasonableness" as defined by me. ;o)

That's fine, to the extent that it intersects with the
one true definition--mine, naturally. Stray outside
that, and you'll find yourself smote. :-)

ACK. ;o)
 

Posts:37,103
Registered: 3/30/99
Re: Reversing LinkedList elements  
Aug 8, 2004 2:40 PM (reply 104 of 142)



 
wouldn't have putting this two shitty *******
together made things a ******* LOT SIMPLER?

Why a GAP of ******* LOOP in between these two
statements ? ??
first.next = null ;first = previous;

Well, Nancy, step through it with a small list--say 4 elements--either on paper or via print statements and see what is happening. If you take your time, and think a little bit, you'll either come to understand the logic, or convince yourself that it's flawed.

Now, most likely, you'll just take a quick look at it, decide that since it doesn't fit your immediate impression of how things should be, that it must be flawed, and you must be right. Resist that impulse. Question your own thinking. Don't look at it going "what's wrong with this thing?" Look at it going, "What's wrong with my understanding of this thing?"
 
This topic has 142 replies on 10 pages.    « Previous | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | Next »