Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8642577
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T11:48:43+00:00 2026-06-12T11:48:43+00:00

So i am trying to compile my LinkedList for a program that i have

  • 0

So i am trying to compile my LinkedList for a program that i have created and it is coming back with errors that i feel are really errors (if that makes since). I am wondering if anyone can look at this and put in their thoughts of why i might be getting errors when i compile and if they have any suggestions on what i should do to get rid of them:

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();
            }
        }

}

Also, is there a way that i can make this code more simpler to read, understand, not as long but yet still have the same task to complete? Please feel free to share.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T11:48:44+00:00Added an answer on June 12, 2026 at 11:48 am

    You have defined an interface and are using it as class..

    public interface LinkedListDS<E> implements ListADT<E> {
    

    Problems in above declaration: –

    • Interface does not implement other interface, they extend, just like a class extends another class..
    • Interface does not define methods and constructors

    So, you wanted to use a class actually..

    Change the above declaration to: –

    public class LinkedListDS<E> implements ListADT<E> {
    

    Also, you haven’t closed your iterator method..

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

    Add a closing brace.. Actually, you have so many of them… Re-indent your code to check the matching braces.. That is one major problem you face when you are not indenting the code..

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When trying to compile the following code, I am getting a warning that line
While trying to compile my project, that uses some third party headers, with mingw
I am trying to improve my C++ by creating a program that will take
I am trying to write a program in C language(code::blocks in windows). I have
I am trying to compile a very simple C program. Installed MinGW using auto
When trying to compile a solution that contains a project with a reference to
When trying to compile the following file in xcode: http://openkinect.org/wiki/C%2B%2BOpenCvExample I get these errors:
I'm trying to compile a Delphi 7 project that I've inherited, and I'm getting
Trying to implement a function in my linkedlist class that will return total amount
I'm trying to create an implementation of a LinkedList that represents polynomials. The Linked

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.