1 Replies - 479 Views - Last Post: 18 December 2012 - 07:28 PM Rate Topic: -----

#1 Norvelle  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 18-December 12

Where do I start/end my main method in this program? Very new to JAVA

Posted 18 December 2012 - 06:25 PM

import java.util.*;

// creating public class
public class IterableList implements Iterable<String>
{
	public static void main(String[] args) {}


private Node head;
public Iterator<String> iterator()
{
return new LLIterator();
}
// private class
private class LLIterator implements Iterator<String>
{
private Node current = head;
public boolean hasNext()
{
return current != null;
}
public String next()
{
String item = current.data;
current = current.next;
return item;
}
public void remove() {}
}
private class Node
{

	// to the next chain item & data portion of the node and empty method.
private String data;
private Node next;
private Node(String item)
{
data = item;
next = null;
}
}
public IterableList ()
{
head = null;
}

// insert method


public void insert(String item)
{
    Node node = new Node(item);
    Node cur = head, back = null;

    if (head == null)
    {
      head = node;
    }
    else{
      while(cur != null && cur.data.compareTo(item) <= 0)
      {
        back = cur;
        cur = cur.next;
      }
      if(back != null && back.data.compareTo(item) == 0);

      else if(back == null)
      {
        head = node;
        node.next = cur;
      }
      else if(cur == null)
      {
        back.next = node;
        node.next = cur;
      }
        else
        {
          back.next = node;
          node.next = cur;

        }
}
}
//insert void
public void delete(String item)
{
Node cur = head, back = null;
boolean found = false;
while (cur != null)
{
if (cur.data == item)
{
if (back == null)
head = cur.next;
else
back.next = cur.next;
break;
} else

{
back = cur;
cur = cur.next;
}
}
}
}


Is This A Good Question/Topic? 0
  • +

Replies To: Where do I start/end my main method in this program? Very new to JAVA

#2 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 5205
  • View blog
  • Posts: 13,951
  • Joined: 18-April 07

Re: Where do I start/end my main method in this program? Very new to JAVA

Posted 18 December 2012 - 07:28 PM

Well the line....

public static void main(String[] args) {}



See the {} at the end? That is the beginning and end of the main function. Everything you want to call and do at the start of your program will be in between those curly braces...

public static void main(String[] args) {
   IterableList myList = new IterableList();

   // Do stuff here with your list called "myList"
}



I think this is what you are asking. If not, please add more details on the trouble you are having. Thanks!

:)
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1