Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

Java 

Creating linked list without using the imported class

I am trying to do an assignment in my Java class. I currently have it working, but I am using a linked list and it's methods in Java. To learn better, our professor wants us to make our own linked list and methods with it. It is for a calculator that uses a stack. I will post part of the code that shows it working using the predefined linked list, but I don't know how to make it myself and was going to see if I could get some help.



Code
LinkedList<Constant> constantlist=new LinkedList<Constant>();    //can't use this

                else if ((s.substring(0,2).equals(":=")) && (s.length() > 2)) {
                    char c = s.charAt(2);
                    if ((c>='a') && (c<= 'z') || (c>='A') && (c<= 'Z'))
                    {
                        s=s.substring(2);
                        for (int i=0; i< s.length(); i++)
                        {
                            if(!Character.isJavaIdentifierPart(s.charAt(i))) {
                                System.out.println("Error: invalid identifier.");
                                System.exit(1);
                            }
                        }
                        if (constantlist != null)
                        {
                            for (int i = 0; i < constantlist.size(); i++) {
                            if (s.equals(constantlist.get(i).name)==true)
                            {
                            System.out.println("ERROR: name already defined.");
                            System.exit(1);
                            }
                            }
                            constantlist.add(new Constant(s, stack.peek() , true));
                            System.out.println("Added constant " + s + " with value " + stack.peek());
                        }
                    }
                }
                    else {
                        for (int i = 0; i < constantlist.size(); i++) {
                            if (s.equals(constantlist.get(i).name)==true) // check if exists as a constant
                            {
                                foundconstant=true;
                                stack.push(constantlist.get(i).data); // if it does, use that value
                            }
                        }
                        if (foundconstant==false) {
                                    System.out.println("Didn't recognize input. Exiting.");
                                    System.exit(1);    
                                }



class Constant{
public String name;
public double data;
public boolean isconstant;



Constant(String n, double d, boolean c) {
    name = n;
    data = d;
    isconstant = c;
  }

}


Possibly Related Threads...
Thread / Author Replies Views Last Post
[C] by lockheadApr 22, 2021 07:10 AM 0 146 Apr 22, 2021 07:10 AM
Last Post: lockhead
[C#] by Sanchez SalesJun 18, 2020 08:11 AM 0 163 Jun 18, 2020 08:11 AM
Last Post: Sanchez Sales
[C] by g4143Dec 28, 2019 09:24 AM 1 347 Dec 28, 2019 09:24 AM
Last Post: an balker