k3y's Profile User Rating: -----

Reputation: 36 Craftsman
Group:
Active Members
Active Posts:
205 (0.23 per day)
Joined:
25-February 12
Profile Views:
5,167
Last Active:
User is offline Apr 12 2013 08:16 AM
Currently:
Offline

Previous Fields

Country:
US
OS Preference:
Windows
Favorite Browser:
Chrome
Favorite Processor:
Intel
Favorite Gaming Platform:
Classic
Your Car:
Pontiac
Dream Kudos:
0

Latest Visitors

Icon   k3y has not set their status

Posts I've Made

  1. In Topic: Linked List Reversal [problem]

    Posted 21 Mar 2013

    @pbl, thank you for all of your help and suggestions. I have some functional code now =D you are the man!
    package linkedlistreversalassignment;
    
    /**
     *
     * @author Patrick
     */
    public class LinkedListReversalAssignment{
        public static void main(String[] args) {
            UnorderedLinkedList <String> stringList = 
                    new UnorderedLinkedList <>();
            
            stringList.insertLast("a");
            stringList.insertLast("b");
            stringList.insertLast("c");
            stringList.insertLast("d");
            
        
            stringList.print();
            System.out.println();
            reverse(stringList);
        }
    
        private static void reverse(UnorderedLinkedList<String> stringList) {
            UnorderedLinkedList tempList = new UnorderedLinkedList<>();
            int length = stringList.length();
            for(int x = 0; x < length; x++){
                tempList.insertFirst(stringList.first);
                stringList.deleteNode(stringList.first.info);
            }
            tempList.print();
        }
    }
    
    
  2. In Topic: Linked List Reversal [problem]

    Posted 21 Mar 2013

    View Postpbl, on 21 March 2013 - 02:35 PM, said:

    Dont't understand your text on x they should be all the same

    if you remove first from 1,2,3,4
    and you insert first in the other it will contain
    1
    2,1
    3,2,1
    4,3,2,1

    The UnorderedLinkedListClass doesn't have a remove method :stuart: how could I create this? or am I way over looking this?
  3. In Topic: Linked List Reversal [problem]

    Posted 21 Mar 2013

    After a few minutes of messing around. I have conjured up this.
    private static void reverse(UnorderedLinkedList<String> stringList) {
            UnorderedLinkedList tempList = new UnorderedLinkedList<>();
            int length = stringList.length();
            for(int x = 0; x < length; x++){
                if(x == 0){
                    tempList.insertFirst(stringList.first);
                }
                else if (x > 0 && x < length) {
                    tempList.insertFirst(stringList.first.link);
                    x+=2;
                    
                }
                else{
                    tempList.insertFirst(stringList.last);
                    x++;
                }
            }
            tempList.insertFirst(stringList.last);
            tempList.print();
        }
    }
    
    

    I know that it is ugly but, with your help I can accomplish this to work the right way =D... please help = :dontgetit:
  4. In Topic: Linked List Reversal [problem]

    Posted 20 Mar 2013

    So all I'll have to do is:
    private static void reverse(UnorderedLinkedList<String> stringList) {
            LinkedList xx = new LinkedList<String>();
            int length = stringList.length();
            for(int i = 0; i < length; i++){
                xx.insertFirst(stringList.delete(0));
            }
            for(int i = 0; i < length; i++){
                stringList.insertLast(xx.delete(0));
             }
        }
    }
    
    

    ... I plan to test this once I am near a computer to compile... if this works, thank you for all the help if not... I will post again
  5. In Topic: Linked List Reversal [problem]

    Posted 20 Mar 2013

    I think I am on the right path
        private static void reverse(UnorderedLinkedList<String> stringList) {
            LinkedList xx = new LinkedList<String>();
            int length = stringList.length();
            for(int i = 0; i < length; i++){
                xx.addFirst(stringList.back());
            }
            for(int i = 0; i < length; i++){
                stringList.insertLast(xx.remove(0));
            
        }
        }
    }
    
    

    is there a way that I could type cast my original list to be a standard LinkedList like the sample you showed me? Or would I have to create new method(s) in order to achieve this result?

My Information

Member Title:
D.I.C Head
Age:
20 years old
Birthday:
July 12, 1994
Gender:
Interests:
Music,
Movies,
Code.
Years Programming:
1
Programming Languages:
Batch,
Bash,
Python,
C++,
Java

Contact Information

E-mail:
Private

Friends

Comments

k3y has no profile comments yet. Why not say hello?