bdmullin's Profile User Rating: -----

Reputation: 0 Apprentice
Group:
Members
Active Posts:
26 (0.03 per day)
Joined:
15-April 11
Profile Views:
569
Last Active:
User is offline Jun 13 2012 07:34 PM
Currently:
Offline

Previous Fields

Country:
US
OS Preference:
Linux
Favorite Browser:
FireFox
Favorite Processor:
Intel
Favorite Gaming Platform:
XBox
Your Car:
Pontiac
Dream Kudos:
0

Latest Visitors

  • Photofrolit Icon
    12 Oct 2011 - 19:55
Icon   bdmullin has not set their status

Posts I've Made

  1. In Topic: AS3 Grab HTML from a website into String?

    Posted 10 Jun 2012

    No responses yet... if it helps I can post some as3 code or links to similar work. I am just not sure what the next step is or where to start.
  2. In Topic: Can't figure out why list is null.

    Posted 12 Oct 2011

    Hey guys, everyone must have been in bed when I posted last. My coffee fueled night helped me solve the lab and the issues I was having. Here is the final code for my SList.java. Thanks for reading, hope this helps someone out.
    class SList implements List
    {
    	private SListNode 	head, 		//Reference to the beginning of the list
    						cursor;		//Reference to current cursor position
    	public SList()					//Constructor: default size
    	{
    		setup();
    	}
    	public SList(int size)		//Constructor: specific size (used for arrays, otherwise neglect)
    	{
    		setup();
    	}
    	public void setup ()	//Called by constructors only.
    	{
    		head = null;
    		cursor = null;
    	}
    	public void insert(Object newElement)
    	{
    		if (newElement == null || isFull())
    		{
    			System.out.println("The element is null or the list is full.");
    		}
    		if (head == null)
    		{
    			head = new SListNode(newElement, null);
    			cursor = head;
    		}
    		else
    		{
    			cursor.setNext(new SListNode(newElement, cursor.getNext()));
    			cursor = cursor.getNext();
    		}
    	}
    	public void remove()
    	{
    		SListNode 	p,		//One to be removed
    		q;		//Prior element
    		if (isEmpty())
    		{
    			System.out.println ("List is empty. Nothing removed.");
    		}
    		else if (cursor == head)							//Remove first element
    		{
    			p = head;
    			head = head.getNext();
    			cursor = head;
    		}
    		else if (cursor.getNext() != null)			//Remove middle element
    		{
    			p=cursor.getNext();
    			cursor.setElement(p.getElement());
    			cursor.setNext(p.getNext());
    		}
    		else										//Remove last element
    		{
    			p=cursor;
    			//Needs work
    			//for(q = head; q.getNext() != cursor; q = q.getNext())
    			q=head;
    			while (q.getNext() != cursor)
    			{
    				q=q.getNext();
    			}
    			q.setNext(null);
    			cursor = head;
    		}
    	}
    	public void replace(Object newElement)
    	{
    		if (newElement == null || isEmpty())
    		{
    			System.out.println("List is empty. Nothing replaced.");
    		}
    		cursor.setElement(newElement);
    	}
    	public void clear()
    	{
    		head = null;
    	}
    	public boolean isEmpty()
    	{
    		if (head == null)
    			return true;
    		else
    			return false;
    	}
    	public boolean isFull()
    	{
    		//Can be adopted for array lists with simple if statement.
    		return false;
    	}
    	public boolean gotoBeginning()
    	{
    		if (!isEmpty())
    		{
    			cursor = head;
    			return true;
    		}
    		else
    			return false;
    	}
    	public boolean gotoEnd()
    	{
    		if (!isEmpty())
    		{
    			while (cursor.getNext() != null)
    			{
    				cursor = cursor.getNext();
    			}
    			return true;
    		}
    		else 
    			return false;
    	}
    	public boolean gotoNext()
    	{
    		if (cursor.getNext() != null)
    		{
    			cursor = cursor.getNext();
    			return true;
    		}
    		else
    			return false;
    	}
    	public boolean gotoPrior()
    	{
    		SListNode p;			//Pointer to the prior node.
    		if (cursor != head)
    		{
    			p=head;
    			while (p.getNext() != cursor)
    			{
    				p=p.getNext();
    			}
    			cursor =p;
    			return true;
    		}
    		else
    			return false;
    	}
    	public Object getCursor()
    	{
    		if (!isEmpty())
    			return cursor.getElement();
    		else
    		{
    			System.out.println ("List is empty or no elements found.");
    			return null;
    		}
    	}
    	public void showStructure()
    	{
     		if (!isEmpty())
    		{
    			SListNode temp = head;
    			while (temp != null)
    			{
    				if (temp.getElement() == cursor.getElement())
    				{
    					System.out.print("[" + temp.getElement() + "] ");
    				}
    				else
    				{
    					System.out.print(temp.getElement() + " ");
    				}
    				temp = temp.getNext();
    			}
    		}
    		else
    			System.out.println("The linked list is empty.");
    	}
    }
    
    
  3. In Topic: Can't figure out why list is null.

    Posted 11 Oct 2011

    Sorry, here is the code:

    //--------------------------------------------------------------------
    //
    //  Laboratory 7                                       TestSList.java
    //
    //  Test program for the operations in the List ADT
    //
    //--------------------------------------------------------------------
    
    import java.io.*;
    import java.util.StringTokenizer;
    
    class TestSList
    {
        public static void main( String [] args ) throws IOException 
        {
            SList testList = new SList( );   // A singly linked list
            char testElement = 'c';          // List element
            char cmd = 'q';                  // Input command
    
            String aToken;                   // A single token in line read
            
            //-----------------------------------------------------------------
            // Initialize reader - To read a character or line at a time
            BufferedReader reader = 
                                   new BufferedReader(new InputStreamReader(System.in));
            // Tokenize the String read
            StringTokenizer strTokens;          // Tokenizer for a string
            
            System.out.println("\nCommands:");
            System.out.println("  +x  : Insert x after the cursor");
            System.out.println("  -   : Remove the element marked by the cursor");
            System.out.println("  =x  : Replace the element marked by the cursor with x");
            System.out.println("  @   : Display the element marked by the cursor");
            System.out.println("  <   : Go to the beginning of the list");
            System.out.println("  >   : Go to the end of the list");
            System.out.println("  N   : Go to the next element");
            System.out.println("  P   : Go to the prior element");
            System.out.println("  C   : Clear the list");
            System.out.println("  E   : Empty list?");
            System.out.println("  F   : Full list?");
            System.out.println("  M   : Move element marked by cursor to beginning  "
                               + "(Inactive : In-lab Ex. 1)");
            System.out.println("  #x  : Insert x before the cursor                  "
                               + "(Inactive : In-lab Ex. 2)");
            System.out.println("  Q   : Quit the test program");
            System.out.println( );
    
            testList.showStructure( );                      // Output list
            
            do
            {
    
                System.out.print("\nCommand: ");            // Read command
    
                // read entire line
                strTokens = new StringTokenizer(reader.readLine( ));
                
                while ( strTokens.hasMoreTokens( ) )
                {
                    aToken = strTokens.nextToken( );
                    cmd = aToken.charAt(0);
    
                    if ( cmd == '+'  ||  cmd == '='  ||  cmd == '#' )
                    {
                        // check if user entered space after command
                        if ( aToken.length( ) > 1 )
                            aToken = aToken.substring(1);
                        else
                            aToken = strTokens.nextToken( );
    
                        testElement = aToken.charAt(0);
                    }
    
                    switch ( cmd )
                    {
                    case '+' :                                  // insert
                        System.out.println("Insert " + testElement);
                        testList.insert(new Character(testElement));
                        break;
    
                    case '-' :                                  // remove
                        System.out.println("Remove the element marked by the cursor");
                        testList.remove( );
                        break;
    
                    case '=' :                                  // replace
                        System.out.println("Replace the element marked by the cursor "
                                           + "with " + testElement);
                        testList.replace(new Character(testElement));
                        break;
    
                    case '@' :                                  // getCursor
                        System.out.println("Element marked by the cursor is "
                                           + testList.getCursor( ));
                        break;
    
                    case '<' :                                  // gotoBeginning
                        if ( testList.gotoBeginning( ) )
                            System.out.println("Go to the beginning of the list");
                        else
                            System.out.println("Failed -- list is empty");
                        break;
    
                    case '>' :                                  // gotoEnd
                        if ( testList.gotoEnd( ) )
                            System.out.println("Go to the end of the list");
                        else
                            System.out.println("Failed -- list is empty");
                        break;
    
                    case 'N' : case 'n' :                       // gotoNext
                        if ( testList.gotoNext( ) )
                            System.out.println("Go to the next element");
                        else
                            System.out.println("Failed -- either at the end of the list "
                                               + "or the list is empty");
                        break;
    
                    case 'P' : case 'p' :                       // gotoPrior
                        if ( testList.gotoPrior( ) )
                            System.out.println("Go to the prior element");
                        else
                            System.out.println("Failed -- either at the beginning of the "
                                               + "list or the list is empty");
                        break;
    
                    case 'C' : case 'c' :                       // clear
                        System.out.println("Clear the list");
                        testList.clear( );
                        break;
    
                    case 'E' : case 'e' :                       // empty
                        if ( testList.isEmpty( ) )
                            System.out.println("List is empty");
                        else
                            System.out.println("List is NOT empty");
                        break;
    
                    case 'F' : case 'f' :                       // full
                        if ( testList.isFull( ) )
                            System.out.println("List is full");
                        else
                            System.out.println("List is NOT full");
                        break;
    //M
    //M         case 'M' : case 'm' :                   // In-lab Exercise 1
    //M             System.out.println("Move the element marked by the cursor to the "
    //M                                + "beginning of the list");
    //M             testList.moveToBeginning( );
    //M             break;
    
    //#            
    //#         case '#' :                              // In-lab Exercise 2
    //#             System.out.println("Insert " + testElement 
    //#                                + " before the " + "cursor");
    //#             testList.insertBefore(new Character(testElement));
    //#             break;
    
                    case 'Q' : case 'q' :                   // Quit test program
                        break;
    
                    default :                               // Invalid command
                        System.out.println("Inactive or invalid command");
                    }
    
                    testList.showStructure( );                     // Output list
                    System.out.println( );
                    
                } // while ( moreTokens )
            }
                while ( cmd != 'Q'  &&  cmd != 'q' );
        } // main
        
    } // class TestSList
    


    class SListNode 
    {
    	private Object element;			//List element
    	private SListNode next;			//Reference to the next element
    	
    	SListNode (Object element, SListNode nextPtr)
    	{
    		this.element = element;
    		next = nextPtr;
    	}
    	//Class methods used by client class
    	
    	SListNode getNext ()			//Return reference to next element
    	{
    		return next;
    	}
    	Object getElement ()			//Returns the element in the current position
    	{
    		return element;
    	}
    	SListNode setNext (SListNode nextVal)	//Set reference to next element
    	{										//& return that reference.
    		return (next = nextVal);
    	}
    	void setElement (Object newElem)		//Set current element to newElem
    	{
    		element = newElem;
    	}
    }
    
    


    public interface List {
    	public static final int DEF_MAX_QUEUE_SIZE = 10;
    	
    	//List manipulation operations
    	public void insert(Object newElement);		//Insert Object after cursor
    	public void remove();						//Remove element at cursor
    	public void replace(Object newElement);		//Replace element at cursor
    	public void clear();						//Remove all elements from list
    	
    	//List status operations
    	public boolean isEmpty();					//Returns T if list is empty
    	public boolean isFull();					//Returns T if list is full
    	public boolean gotoBeginning();				//Moves cursor to beginning of list
    	public boolean gotoEnd();					//Moves cursor to end of list
    	public boolean gotoNext();					//Moves cursor to next element in list
    	public boolean gotoPrior();					//Moves cursor to preceding element
    	public Object getCursor();					//Returns the element at the cursor
    	public void showStructure();				//for testing/debugging purposes
    }
    
    
  4. In Topic: Can't figure out why list is null.

    Posted 11 Oct 2011

    I dont want to add all that. I should have all the methods and classes I need. I attached SListNode and a few other files in the original post in a .zip.
  5. In Topic: Can't figure out why list is null.

    Posted 11 Oct 2011

    True, the is full part was in case we reused this with an array. That is why there are different constructors as well. Incase we needed to change it and use an array. Professors request.

    Anway, any luck with why it is null?

My Information

Member Title:
New D.I.C Head
Age:
23 years old
Birthday:
March 27, 1990
Gender:
Location:
Michigan
Full Name:
Brant David Mullinix
Years Programming:
2
Programming Languages:
Java
VB

Contact Information

E-mail:
Private

Friends

bdmullin hasn't added any friends yet.

Comments

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