2 Replies - 263 Views - Last Post: 09 October 2012 - 06:08 PM Rate Topic: -----

#1 NewGuy2Prog  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 09-October 12

Getting errors messages when trying to compile my LinkedList file

Posted 09 October 2012 - 05:29 PM

So i have created a LinkedList file that i can not seem to get to compile. I was wondering if anyone could correct the code to make it compile. Sorry i am a beginner to programming so please forgive my foolishness.

 package data_structures;

import java.util.Iterator;
import java.util.NoSuchElementException;

public class LinkedListDS<E> implements ListADT<E> {
	class Node<E> {
		E data;
		Node<E> next; 

		public Node(E data) {
			this.data = data;
			next = null;
			}
		}

	private Node<E> head, tail;
	private int currentSize;

	public LinkedListDS() {
		head = tail = null;
		currentSize = 0;
		}

	public void addFirst(E obj) {
		if(head == null)
			head = tail = newNode;
		else 
			newNode.next = head;
			head = newNode;
			currentSize++;
			}	

//  Adds the Object obj to the end of the list 
	public void addLast(E o) {
		if(head == null)
			head = newNode;
			tail = newNode;
			currentSize++;
			return;
			{
			tail.next = newNode;
			tail = newNode;
			currentSize++;
			}
		}	

//  Removes the first Object in the list and returns it.
//  Returns null if the list is empty.
    public E removeFirst() {
		if(head == null) 
			return null;
		E tmp = head.data;
		head = head.next;
		{
		if (head == null)
			tail = null;
		currentSize++;
		return tmp;
		}
	}

//  Removes the last Object in the list and returns it.
//  Returns null if the list is empty.
	public E removeLast() {
		Node<E> previous = null;
		Node<E> current = head;
			if (current == null) 
				return null;
			while(current.next != null) {
				previous = current;
				current = current.next;
			}
			if(previous = null)
				return removeFirst;
				previous.next = null;
				tail = previous;
				currentSize--;
			return current.data;
			}

//  Returns the first Object in the list, but does not remove it.
//  Returns null if the list is empty.
	public E peekFirst() {
		if(head == null)
			return null;
		return head.data;
		}

//  Returns the last Object in the list, but does not remove it.
//  Returns null if the list is empty.
	public E peekLast() {
		if(tail == null)
			return null;
		return tail.data;
		}

//  Removes the specific Object obj from the list, if it exists.
//  Returns true if the Object obj was found and removed, otherwise false
	public boolean remove(E obj) {
		if(head == null)
			return false;
			{
		if(head.data.equals(obj))
			head = head.next;
			return true;
			}
	Node<E> current = head;
	while(current.next != null)
	{
		if(current.next.data.equals(obj))
		{
			current.next = current.next.next;
			return true;
			}
			current = current.next;
			}
			currentSize--;
			return false,
		}

//  The list is returned to an empty state.
	public void makeEmpty() {
		head = tail = null;
		currentSize = 0;
		}
	

//  Returns true if the list contains the Object obj, otherwise false
	public boolean contains(E obj) {
		Node<E> current = head;
		while(current != null)
		{
			if(current.data.equals(obj)
				return true;
				}
			current = current.next;
				return false;
				}

//  Returns true if the list is empty, otherwise false
	public boolean isEmpty() {
		return = null;
		}

//  Returns true if the list is full, otherwise false
	public boolean isFull() {
		return false;
		}

//  Returns the number of Objects currently in the list.
	public int size() { return currentSize; }

	public iterator<E> iterator() { return new iterator; }

	class IteratorHelper implements Iterator<E> {
		Node<E> iteratorPointer;
		public IteratorHelper() {
			iteratorPointer = head;
			}
		public boolean hasNext() {
			return iteratorPointer != null;
			}
		public E next() {
			if(!hasNext())
				throw new NoSuchElementException();
			E tmp = iteratorPointer.data;
			iteratorPointer = iteratorPointer.next;
			return tmp;
			}
		public void remove() {
			throw new UnsupportedOperationException();
			
		}

}




When i compile this file, i continue to receive that following error messages:

javac LinkedListDS.java
LinkedListDS.java:178: class, interface, or enum expected
}
^
1 error

Is This A Good Question/Topic? 0
  • +

Replies To: Getting errors messages when trying to compile my LinkedList file

#2 Kinaces  Icon User is offline

  • D.I.C Head

Reputation: 78
  • View blog
  • Posts: 230
  • Joined: 04-October 12

Re: Getting errors messages when trying to compile my LinkedList file

Posted 09 October 2012 - 05:34 PM

This code is just a mess with errors.
Very hard to fix compile errors when there isn't the complete source.

Although first thing I found was that you never ended your inner class. There is never a closing bracket.

This post has been edited by Kinaces: 09 October 2012 - 05:34 PM

Was This Post Helpful? 0
  • +
  • -

#3 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8343
  • View blog
  • Posts: 31,887
  • Joined: 06-March 08

Re: Getting errors messages when trying to compile my LinkedList file

Posted 09 October 2012 - 06:08 PM

Please indent your code properly
if you do so you'll see that you have unmatched {}
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1