0

We were given 3 problems but our professor wants us to convert it and work it on NetBeans.

I encountered a lot of errors that did not came out from my NotePad++.

Can you please help me with this? Later on I will proceed to add another question that I could not answer to my self.

A little Guide will also help, thanks in advance :)

Code:

package datastructures;
    public class StackArray {
        private static class Node {

            public Node() {
            }
        }
        private Node top;

        public StackArray()
        {
            top = null;
        }

        public boolean isEmpty()
        {
            return top == null;
        }

        public boolean isFull()
        {
            return false;
        }

        public boolean push(String item)
        {
            Node newNode = new Node();
            newNode.info = item;

            if(isEmpty())
            {
                top = newNode;
            }
            else
            {
                newNode.next = top;
                top = newNode;
            }
            return true;
        }

        public String peek()
        {
            if(!isEmpty())
                return top.info;
            else
                return null;
        }

        public boolean pop()
        {
            String itemPeek = peek();
            if(itemPeek != null)
            {
                top = top.next;
                return true;
            }
            else
                return false;
        }

        @Override
        public String toString()
        {
            String output = "";

            if(!isEmpty())
            {
                Node temp = top;
                while(temp != null)
                {
                    output+="["+temp.info+"]\n";
                    temp = temp.next;
                }
            }

            return output;
        }
    }

The Errors I got were:

.info .next

it also shows when run

*No Class Found

1
  • "were .info .next it also shows when run *No Class Found" What do you mean by this? Commented Feb 13, 2014 at 6:29

1 Answer 1

3

Basically, Node has no properties, so newNode.info, newNode.next etc are all undefined properties.

You need to supply these as instance variables within your Node class.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.