Project 1999

Go Back   Project 1999 > Red Community > Red Rants and Flames

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #11  
Old 10-16-2015, 12:09 PM
Chronoburn Chronoburn is offline
Fire Giant


Join Date: Jun 2011
Location: Minneapolis
Posts: 547
Default

LinkedList<Integer> list = new LinkedList<Integer>();

Quote:
Originally Posted by SamwiseRed [You must be logged in to view images. Log in or Register.]
Code:
//naw naw
//15 Feb 2015
//IntNode.java

import java.util.*;

public class IntNode{

   //instance variables
   private IntNode link;
   private int value;
   
   //---Constructors---
   IntNode(){
      link = null;
      value = 0;
   }//end default constructor
   
   IntNode(int d, IntNode n){
      link = n;
      value = d;
   }//end constuctor
   
   //---getters---
   public IntNode getLink(){
      return link;
   }//end getLink
   
   public int getValue(){
      return value;
   }//end getValue
   
   //---setters---
   public void setLink(IntNode n){
      link = n;
   }//end setLink

   public void setValue(int d){
      value = d;
   }//end setValue
   
   public String toString(){
   
      String str = "";
      
      for(IntNode cursor = this; cursor != null; cursor = cursor.link)
         str += cursor.value + " ";
         
      return str;
   
   }//end toString method
   
   public static int listLength(IntNode head){
      int answer = 0;
      
      for(IntNode cursor = head; cursor != null; cursor = cursor.link)
         answer++;
         
      return answer;
   }//end listLength

   public static void main(String args[]){
   
      IntNode node6 = new IntNode(6, null);
      IntNode node5 = new IntNode(5, node6);
      IntNode node4 = new IntNode(4, node5);
      IntNode node3 = new IntNode(3, node4);
      IntNode node2 = new IntNode(2, node3);
      IntNode node1 = new IntNode(1, node2);
      System.out.println(node1);
      
      System.out.println(listLength(node1));
   
   }//end main

}//end class IntNode
 


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 05:27 AM.


Everquest is a registered trademark of Daybreak Game Company LLC.
Project 1999 is not associated or affiliated in any way with Daybreak Game Company LLC.
Powered by vBulletin®
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.