//couldn't find a better way to do this... public void double2 ( ) { /* Invariant is L with 2 first ones and rest*/ ListNode q, w; w = q = new ListNode (null); for (ListNode p = myHead; p != null; p = p.myRest) { q.myRest = new ListNode(p.myFirst, p); q = q.myRest.myRest; } myHead = w.myRest; /*ListNode p = myHead; ListNode p1 = myHead.myRest; ListNode p2 = myHead.myRest.myRest; myHead = new ListNode (p.myFirst, p); myHead.myRest.myRest = new ListNode (p1.myFirst, p1); myHead.myRest.myRest.myRest.myRest = new ListNode (p2.myFirst, p2); */ } public void double3 ( ) { ListNode w; w = new ListNode (myHead.myFirst); for (ListNode p = myHead; p != null; p = p.myRest) { w.myRest= new ListNode(p.myFirst, p); w = w.myRest.myRest; System.out.println(this.toString()); } myHead = new ListNode (myHead.myFirst, myHead); }
Saturday, November 17, 2007
Doubling a Linked List
Subscribe to:
Post Comments (Atom)
Just some daily notes ...
Things I'm into now...
Blog Archive
-
▼
2007
(29)
-
▼
November
(14)
- Declaring an Edge Adjacency List Graph
- MaximallyBalanced or Complete Binary Tree
- Calculating the Height of a Tree
- Adding to a Circular Doubly Linked List
- 3 ways to REVERSE a list (singly linked)
- Reversing a List Iteratively!
- Doubling a Linked List
- Access Modifiers: public, private, proctecd, packa...
- End of HFJ
- Format Specifiers
- Collection class tidbits...
- Generic class definitions and one implementation
- doubling a List
- Don't Forget Your Scheme!
-
▼
November
(14)
No comments:
Post a Comment