Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 1 of 1

Thread: LinkedIntLists issue - how can i move links without creating nodes?

  1. #1
    Junior Member
    Join Date
    Oct 2009
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default LinkedIntLists issue - how can i move links without creating nodes?

    The objective:


    Write a method called removeEvens that removes the values in even-numbered indexes from a list, returning a new list that contains those values in their original order.

    For example, consider a variable
    list1 that stores values { 1, 2, 3, 4, 5, 6 }

    If the following call is made:

    LinkedIntList list 2 = list1.removeEvens();

    Then --

    List1 { 2, 4, 6 }
    List2 { 1, 3, 5 }


    Restrictions: You may not call any methods of the class other than the constructor.
    You may not create new nodes nor change the values stored in data fields.
    You must solve it by rearranging the links of the list.


    The greatest trouble i have with this problem is that I can only work with the two lists at hand and can't create any new nodes or a like. I'm having a hard time trying to think how I could get the program to actually loop through the list and change up the links

    So far I have made two test cases to check - if the list either has no data, or has only one data.

    My Question: How can I loop through the initial list A, and relink all the nodes without actually creating new nodes, without calling other methods, cannot change the datafields. How can i rearrange the links for any number of # data in a list. Any pointers will be greatly appreciated! I just can't wrap my mind around this one when it deals with X amount of data beyond 1 data set.



    		public LinkedIntList removeEvens(){
    		LinkedIntList b = new LinkedIntList();
    		b.front=front; // Points list B to front.  
     
    		if(front == null) { // If list is empty, output notice.  
    			System.out.println("The list inputed it empty");
    		}if(front.next == null){// If list has one value, give it to list B and remove from list A. 
    			front = null;
    		}else{ // If the list has two or more values, do this.  
    			front = front.next;
    			b.front.next = b.front.next.next;
     
     
    			while(front.next != null){
     
    			}
     
    		}
    		return b;
    	}
     
     
    }
    Last edited by bh-chobo; December 1st, 2010 at 04:31 AM.


Similar Threads

  1. How to enumarete Network Nodes using Java
    By dilshadpaleri in forum Java Networking
    Replies: 0
    Last Post: September 7th, 2010, 06:45 AM
  2. changing the visited links color in JEditorpane
    By nasi in forum AWT / Java Swing
    Replies: 5
    Last Post: April 18th, 2010, 08:44 AM
  3. How to move an image (or how to delete one)
    By User in forum AWT / Java Swing
    Replies: 3
    Last Post: December 17th, 2009, 11:25 AM
  4. Want to move my button away from center.
    By Fendaril in forum AWT / Java Swing
    Replies: 2
    Last Post: November 6th, 2009, 10:05 PM
  5. Having trouble redirecting nodes
    By KingLane in forum Collections and Generics
    Replies: 6
    Last Post: October 19th, 2009, 06:46 PM