CircularLinkedList.... Ahhh

So, I managed to make a LinearLinkedList and DoublyLinkedList without any problems. However, I'm currently making a CircularLinkedList and I need a little help. I can't get the implementation for Object removeFirst() and Object removeLast(). Now, I want to finish this without resorting to making a CircularDoublyLinkedList, so I can't put a getPrev() method in. Anyway, here is the code!
Here is the interface first of all. Most of the comments comes from the book that I am reading with.
ListNode.java
     * The "value" data field is of type "Object," which means that primitive types like "int"
     * cannot be placed directly into a ListNode. They must first be wrapped in a wrapper class like
     * "Integer."
    private Object value;
     * The ListNocde class is said to be "self-referential," since it has an instance variable
     * "next" that refers to itself. Self-referential objects can be linked together to form objects
     * like lists, trees, stacks, and so on. Thus the variable "next" is called a "link" or
     * "pointer."
    private ListNode next;
     * The ListNode constructor, with initValue and initNext parameters, allows a single statement
     * to assign the "value" and "next" fields to a ListNode.
     * @param initValue sets the value of this node
     * @param initNext sets value of the next node
    public ListNode(Object initValue, ListNode initNext)
        value = initValue;
        next = initNext;
     * This is an accessor method that returns the value of the current ListNode. Since the type is
     * Object, a cast to "Integer, Double, or String," and so on will be needed, unless you plan to
     * assign it to a variable of type Object.
     * @return the value of this node
    public Object getValue()
        return value;
     * This is an accessor method that returns "next," the pointer value of the the current
     * ListNode.
     * @return the value of the next node
    public ListNode getNext()
        return next;
     * This is a mutator method that allows the "value" of the current ListNode to be changed to
     * "theNewValue."
     * @param theNewValue the new value of the node
    public void setValue(Object theNewValue)
        value = theNewValue;
     * This is a mutator method that allows the "next" field of the current ListNode to be changed
     * to "theNewNext."
     * @param theNewNext the new pointer value of the next node
    public void setNext(ListNode theNewNext)
        next = theNewNext;
}And here is the CircularLinkedList.java
import java.util.NoSuchElementException;
public class CircularLinkedList
    private ListNode lastNode;
    private int size;
    //Construct an empty list
    public CircularLinkedList()
        size = 0;
        lastNode = null;
    //Return true if list is empty, false otherwise
    public boolean isEmpty()
        return size == 0;
        //or return lastNode == null;
    //Return number of nodes in the list
    public int size()
        return size;
    //This method is needed for client traversal of list.
    //Returns reference to first node
    public ListNode getlastNode()
        return lastNode;
    //Insert Object obj at front of list
    public void addFirst(Object obj)
        if(isEmpty())
            lastNode = new ListNode(obj, null);
            lastNode.setNext(lastNode);
        else
            ListNode p  = new ListNode(obj, lastNode.getNext().getValue());
            lastNode.setNext(p);
        size++;
    //Insert Object obj at end of list
    public void addLast(Object obj)
        if(isEmpty())
            lastNode = new ListNode(obj, null);
            lastNode.setNext(lastNode);
        else
            ListNode p = new ListNode(obj, lastNode.getNext().getValue());
            lastNode.setNext(p);
            lastNode = p;
        size++;
    //Remove and return first element
   public Object removeFirst()
        if(isEmpty())
            throw new NoSuchElementException("Can't remove from empty list");
        //what goes in here?
        size--;
        return item;
    //Remove and return last element
    public Object removeLast()
        if(isEmpty())
            throw new NoSuchElementException("Can't remove from empty list");
    //what goes in here?
        size--;
    //Return CircularLinkedList as String
    public String toString()
        if(isEmpty())
            return "empty.";
        else
            String s = "";
            ListNode current = lastNode.getNext();
            while(current != lastNode)
                s = s + current.getValue() + " ";
                current = current.getNext();
            s = s + current.getValue();
            return s;
}Thanks in advance guys!

ok yjis is the code but is not well codified so is a kinf�d of messy, But it works.
public class Node {
    public Node next;
    private int data;
    /** Creates new Node */
    public Node(int info) {
        data=info;
    public String Print () {
        return ("\nData: "+data);
public class List {
   Node ini;
    /** Creates new List */
    public List() {
        ini=null;
    public void AddFirst (int info) {
        Node temp=ini;
        Node NewNode=new Node (info);
        if (ini!=null) {
            while (temp.next!=ini)
                temp=temp.next;
            NewNode.next=ini;
            temp.next=NewNode;
            ini=NewNode;
        if (ini==null) {
            ini=NewNode;
            NewNode.next=ini;
    public Node DelFirst () {
        Node behind=ini;
        if (ini==null) return null;
        if (ini!=null) {
            if (ini.next==ini) {
                ini=null;
                return ini;
            if (ini.next!=ini) {
                while (behind.next!=ini) {
                    behind=behind.next;
                ini=ini.next;
                behind.next=ini;
        return ini;
    public Node DelLast () {
        if (ini==null) return null;
        Node temp=ini;
        Node behind=null;
        if (ini!=null) {
            if (ini.next==ini) {
                ini=null;
                return ini;
            if (ini.next!=ini) {
                while (temp.next!=ini) {
                    behind=temp;
                    temp=temp.next;
                behind.next=temp.next;
                temp.next=null;
        return temp;
    public String Print () {
        String res="";
        Node temp=ini;
        if (temp!=null) {
            res=res+temp.Print ();
            while (temp.next!=ini) {
                temp=temp.next;
                res=res+temp.Print ();
        return res;
public class Test extends java.applet.Applet {
    List Lista;
    /** Initializes the applet Test */
    public void init() {
        Lista=new List ();
        initComponents();
    /** This method is called from within the init() method to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
    private void initComponents() {
        txt = new java.awt.TextField();
        label1 = new java.awt.Label();
        ins = new java.awt.Button();
        delf = new java.awt.Button();
        dell = new java.awt.Button();
        button4 = new java.awt.Button();
        Area = new java.awt.TextArea();
        setLayout(null);
        add(txt);
        txt.setBounds(140, 70, 40, 20);
        label1.setText("Number: ");
        add(label1);
        label1.setBounds(80, 70, 55, 20);
        ins.setLabel("Insert");
        ins.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                insMouseReleased(evt);
        add(ins);
        ins.setBounds(80, 110, 60, 24);
        delf.setLabel("Del first");
        delf.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                delfMouseReleased(evt);
        add(delf);
        delf.setBounds(80, 140, 60, 24);
        dell.setLabel("Del last");
        dell.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                dellMouseReleased(evt);
        add(dell);
        dell.setBounds(80, 170, 60, 24);
        button4.setLabel("Print");
        button4.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                button4MouseReleased(evt);
        add(button4);
        button4.setBounds(80, 200, 60, 24);
        add(Area);
        Area.setBounds(160, 110, 150, 110);
    private void button4MouseReleased(java.awt.event.MouseEvent evt) {
        // Add your handling code here:
        Area.setText (""+Lista.Print ());
    private void dellMouseReleased(java.awt.event.MouseEvent evt) {
        // Add your handling code here:
        Lista.DelLast ();
    private void delfMouseReleased(java.awt.event.MouseEvent evt) {
        // Add your handling code here:
        Lista.DelFirst ();
    private void insMouseReleased(java.awt.event.MouseEvent evt) {
        // Add your handling code here:
        Lista.AddFirst (Integer.parseInt (txt.getText()));
    // Variables declaration - do not modify
    private java.awt.TextField txt;
    private java.awt.Label label1;
    private java.awt.Button ins;
    private java.awt.Button delf;
    private java.awt.Button dell;
    private java.awt.Button button4;
    private java.awt.TextArea Area;
    // End of variables declaration
-----------------------------------------and the html
<HTML>
<HEAD>
   <TITLE>Applet HTML Page</TITLE>
</HEAD>
<BODY>
<H3><HR WIDTH="100%">Applet HTML Page<HR WIDTH="100%"></H3>
<P>
<APPLET codebase=.. code="CircularList/Test.class" width=350 height=200></APPLET>
</P>
<HR WIDTH="100%"><FONT SIZE=-1><I>Generated by NetBeans IDE</I></FONT>
</BODY>
</HTML>

Similar Messages

  • AHHH! "move to" command

    hi,
    been back to mac for a few years now but i still miss my "right click - move to (folder)" command from winxp. did a search for "finder move menu item" and found the solution...for osx 10.5.8. Thus the "AHHH!" in the title. Abracode is available but it uses some kind of shortcut thing that i dont really understand am pretty sure will not give me the simplicity of a "move to" option when i right click. any help for snow leopard would be much appreciated. oh yea, and i know how to move while holding the "apple" key. thanks again.

    Create an Automator Service that accepts Files and Folders in Finder and add a Move Finder Items action. Choose a destination for it to start in, and click on Options and set it to show this action when the workflow runs. Or, you could just pick a destination and make multiple default destination actions without setting the option to show the pick destination dialog.

  • AHHH!!! please read, major help needed

    ok, so i got his brand new iPod nano today...i have been trying to put songs on it for hours! It's notbeing recognized by iTunes or something. and i got this error 1607. I tried the solutions on the apple site, but it doesn't work. I plug in the iPod, it says charging and everything, everything is installed, all of the software, but the updater doesn't see that i have an i Pod plugged in...
    AHHH!!!!!
    help?

    Hi,
    Is this link helpful?
    iTunes for Windows installation quits with 1607 error or while publishing product information
    Regards
    Colin R.

  • Why can I not access My iPhone on my Air - they have the same cloud account - same iTunes - logged onto the same wifi network... and connected via USB - difficult much?!its killing me ahhh my screen smashed and i want access to my iPhone on my macbook

    Why can I not access My iPhone on my Air - they have the same cloud account - same iTunes - logged onto the same wifi network... and connected via USB - difficult much?!its killing me ahhh my screen smashed and i want access to my iPhone on my macbook..
    why is it sooo hard still --- can anyone inform me on this miracle app please
    thank you
    sincerely
    Theigalaxy

    find my iphone is something one needs to activate on the phone itself using the same appelID is nowhere near enough
    if it is then one can track, play a sound and remote whipe it from
    www.icloud.com
    if your screen is smashed and you think you can use find my iphone to get any data from your phone you are sadly mistaken

  • When i restore my iphone i lost everyting my picture ,my contacts, ahhh how i get back my old stuff ?

    when i restore my iphone i lost everyting my picture ,my contacts, ahhh how i get back my old stuff ? i was updating the latest version 6

    You don't.
    Sorry

  • Ahhh! I boke my MB

    I'm planning on upgrading my hard drive to a 160GB soon. But I only have 4 torx screw drivers, I wasn't sure if one was the T8 I need for replacing the metal brace. I took the battery out removed the L bracket and the the drive. After testing the 2 smallest ones; I knew I need to get a T8. Then when I go to slide the drive in it won't slide in all the way!!!!!!!!!!! Ahhh! There's roughly and inch of the drive that wont go in. I can push it a bit more, but I don't want to cause more damage. It feels kinda boing when I push on the drive. And if I don't hold it, it slides back slightly.
    Has this happened before? What should I do? And if I need to send it to Apple, how much?

    Nope I'm sliding it in the right way. Positive, when the computer is upside down, the metal cage goes on top.
    I mean I didn't think it'd be hard to replace!!-Is is possible that there is some rubber padding that as attached to the sides to the drive bay to keep it from slipping that got pushed down to the bottom?
    Actually I am a he. I'm 14 years oold and when I got my Apple ID I was 13 and used my mom's name cuz technically you have to be 13 to use your name. So now I can't change the alias for my account And I don't feel like creating a new one cuz I use it for iTunes and the Apple store.
    I'll check again with a flashlight and see if I can see anything.
    [if there aree typos it's cuz Safari for Win doesn't include Spell Check}

  • "itunes has encountered a problem and needs to close" AHHH i've tried every

    Windows XP
    i get the classic windows 'your program is screwed error message'. I've tried everything, the only thing i have noticed is that when i tried to install quicktime standalone as a possible fix, an error message comes up that says a newer version of quicktime is already installed, even though i searched my computer for any trace of quicktime and nothing came up (including startup). please help..thank you

    i have the exact same problem... spent hours tonight trying to sort it out... its really doing my head in... dont know how many times i have installed itunes and removed it now!!!

  • AHHH "iTunes has encountered a problem and needs to close."

    iTunes has encountered a problem and needs to close.
    AHHHHHHHHHHHHHHHHHHHHHHHHHHHH, im tired of seeing that error as soon as i open up
    soon as i updated it, it stopped working, i've searched searched and searched but i can't find anything, this is really making mad, it won'et let me open it or anything, how do i fix this, what is the deal? there has to be a way around it, to fix it, or another progrma that will add songs to the iPod.

    I have the same problem!
    I have no spyware or anything like that stopping it.
    What else could it be?
    Its happened eve since i restore my computer to the day after i installed it.
    HELP ITS DRIVING ME MAD!
    -Hana xx

  • I just got my ipad and syncd it to my friends computer (now realize this was a mistake) as he is going to leave the country soon with his computer.........ahhh - how do I now syn to my own computer at home?

    a little help please........I just got my ipad and have synced it to my friends computer and now can't sync it to my own home computer........any suggestions?

    https://discussions.apple.com/message/11527071#11527071
    1) Without connecting your iPad to your laptop, start iTunes. Click on Edit. Click on Preferences. Click on Devices. Check the box next to "Prevent your iPod etc. from automatically syncing." Click OK.
    2) Now connect your iPad to your laptop and start iTunes.
    3) When iTunes starts, right click on your iPad under Devices in the left column. Select Transfer purchases etc.
    4) After it finishes transferring all your apps to your new laptop, right click on your iPad and select Backup your iPad.
    5) After it finishes backing up your iPad, right click on your iPad and select Restore etc.
    6) After it finishes restoring, left click on your iPad , then click on the Apps tab on top, and check the box next to Sync Apps, then click on Apply below.
    If everything on your iPad looks good after the sync, go back and click on Edit / Preferences / Devices and UN-check the box next to Prevent your iPod etc. The only other thing you may want to check is if your contacts, bookmarks, etc. are syncing correctly now. If not, go to the Info tab after connecting and make sure you indicate which features you want to sync with what sources.
    That should do it.

  • Yellow burn marks coming up from heat vents?!?! Ahhh!

    Hey ya'll
    Just a quick question, the bottom part of my screen, where it connects to the main section of the mac book pro (the hinge) appears to have gone yellow, a burny way that scares me. Am I right to be scared?
    In a vaguely related matter, the Sims appears to be having the odd graphics glitch when loading at the moment, perhaps the whole thing is just on big graphics card overheat?
    Let me know!
    Cheers
    Matty

    Do you have any programs installed that tell you the temperature and fan speeds on your MBP?
    If not, you could download something like
    iStat Pro
    http://www.apple.com/downloads/dashboard/status/istatpro.html
    It tells you the temps, speeds of fans and other things happening on the MBP. There is a specific fan control download but I can't think of the name right now. I would defenitaly get that looked at though.

  • IWeb 08!! (AHHH!!!)

    Hey
    I am one of the many, who is having issues with the new suite of programs. Basically this is my problem:
    I started a website in iWeb 06 and it had been going perfectly and was looking pretty swish. I installed iLife 08, and frantically checked my website. Nothing wrong, Phew! So I carried on working and everything was going nicely, until I published my site. You will be surprised to know that I didn't get a error, however when I went to check my website, I looked at one of the tables I had made and It was all messed up. To tell you the truth they weren't really tables, they were just lines organised to look like tables. Luckily as this is a project for school I have several other versions of the site published into folders and saved. So I took a screenshot of the new version and the old version to show you (See below). So my question to you guys is how do I make a proper table in iWeb? Or how can I get my website looking the way it should?
    http://kumquat.quickshareit.com/share/feestable14c7e4.jpg
    http://grapefruit.quickshareit.com/share/buprices11b5a4.jpg
    Thanks
    Tclare
    Message was edited by: Tcare
    Message was edited by: Tcare

    I wish I had the answers.. until Apple fixes this program.. there will not be any valid answers... I like being used as a beta test subject. Maybe the guys on here that say that we should ask questions and they will help. Maybe they can answer this?
    But the truth of the matter is we got sold something that doesn't work....
    Want to buy a brand new car with out the tires?
    Message was edited by: Dwain Thompson

  • AHHH!  Leopard installation gone awry, please help!

    Okay, so here's what happened. I had my husband's iBook G4, and I was installing Leopard on it, with the idea that he would be happy about it when he got home from work. So I started installing Leopard. At about 1/20th through the installation, my husband got home (it took slower than I expected) and said that he would like to use his computer, and wanted to install it later. So I quit out of the installer, and rebooted to the disk. Now it's stuck on the gray loading screen with the apple on it, and that small circular loading bar, and is has been for a good ten minutes. Any advice? Please, I really need help!

    If it's not too late, here is a suggestion. If you have access to another Mac (yours, a friends, whatever) boot your husbands iBook into target disk mode and copy his data before you do anything else. It's quite possible that in order to recover from the botched install, you will end up having to erase the drive and start over in which case the data will be lost. Also, after you have recovered from this, smack you "producer" husband in the head with a stick and make him go get an external drive to back up his data. Or get him one as an early C-mas gift. Shocking in this day and age to have no backups!
    PS The above assumes you know how to use TD mode. If not, post back for instructions....

  • AHHH why is this happening to me. "STUB NOT FOUND"

    Cannot create remote server
    objectjava.rmi.ServerException: RemoteException occurred in server thread; nested exception is:
    java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:
    java.lang.ClassNotFoundException: RemoteServer_Stub
    Arhhhhhhhhhhhhhh why does it not work. The Stub is in the same folder as the RemoteServer class.
    I am new to RMI so there must be something obvious i have missed out. It keeps on saying that it cannot find the stub class. The Stub class is in the same folder as the normal class and the classpath is set!!!!
    WHAT IS GOING ON?????????????
    Please help,
    Manny thanks,
    Me

    I've got this error several times. When you start running your program your command will look something like this (on UNIX):
    java -classpath /jars/x.jar:/jars/y.jar -Djava.rmi.codebase=file:/export/home/guy_t/
    com.foo.bar.MainClass
    Now, look at the codebase property in the command - it's signifying a directory - in fact, it's signifying a directory on the disk which is used at runtime to load classes. hence, ensure that your stubs are in the codebase and thing will work just fine.
    ON Solaris, I found that you cannot put multiple entries in the codebase property, so you may have to unjar your jar files there.
    HTH,
    Chetan
    Cannot create remote server
    objectjava.rmi.ServerException: RemoteException
    occurred in server thread; nested exception is:
    java.rmi.UnmarshalException: error
    : error unmarshalling arguments; nested exception is:
    java.lang.ClassNotFoundException:
    eption: RemoteServer_Stub
    Arhhhhhhhhhhhhhh why does it not work. The Stub is in
    the same folder as the RemoteServer class.
    I am new to RMI so there must be something obvious i
    have missed out. It keeps on saying that it cannot
    find the stub class. The Stub class is in the same
    folder as the normal class and the classpath is
    set!!!!
    WHAT IS GOING ON?????????????
    Please help,
    Manny thanks,
    Me

  • Ahhh the old wet ipod

    I had to walk in the rain the other day and when I opened my backpack, my IPOD was sitting in about an inch of water. It has a rubber case but there are openings (screen, USB, headphones etc). I let it dry for a couple of days and then plugged it into my computer. It turned on and charged up and I got excited. After charging, I tried using it. The buttons do not work. None of them, including the click wheel. The menu button does not turn it on, BUT it will turn on if I hold the menu and select buttons for the ipod reset. I just did the ipod restore and udpate, no luck. All of my music was intact, even though it's gone now due to the restore.
    I am reading now that you should let it dry for a week and do not turn it on before then. Is there a chance my buttons got fried because it was turned on too soon? Any help is appreciated.
    Thanks
    George

    Copy the ENTIRE iTunes folder from the old computer to the new computer.

  • AHHH! Auditing doesn't work!

    Hello everyone,
    I am trying to audit my users access. For example, i entered this command:
    audit select table by access;
    And it said it was successul. So i go and do some selects in a users account. I then do this:
    select username, timestamp, obj_name, action_name from user_audit_statement;
    But it doesn't show any commands made by my user. I also tried to audit like this:
    audit select table by gary;
    But still it doesn't show up in the auditing tables. Please can someone explain what i am doing wrongly?

    Did you set the AUDIT_TRAIL parameter ?
    See
    http://download-west.oracle.com/docs/cd/B14117_01/serv
    r.101/b10755/initparams015.htm#sthref88I set it to DB, but i have now changed it to db_extended, just to populate the sql_text columns as well.
    So it was set to DB before, and it still wasn't working.
    Any additional ideas?

Maybe you are looking for

  • Media Encoder CS4 does not work

    CS4 Windows 7 Media Encoder does not work!? From PremierePro to the Encoder (fullHD to MPEG2) The encoder is very slow and stops after time. And I see that the encoder try to make a .mpg file but it also makes .m2v and .mpa. in the same time? What to

  • Flash error from Captivated swf files

    I need to load swf files made in Captivate into a Flash file. Everything has gone smoothly except for a Multiple Choice quiz swf which shows this error in Flash: TypeError: Error #1009: Cannot access a property or method of a null object reference.  

  • Maximum size of a URLRequest? [iPhone]

    My UrlRequest hangs at the PROGESS event when the result is too large. Currently, it says 1256 bytesLoaded of 0 bytesTotal.(which is the wrong way around, but it does have these values) and nothing happens. When I change my api to return less data, t

  • Pix501: allow all incoming smtp to one host and all smtp out from one host only

    I have a pix501 and I have a mail server. What I would like to do is ensure that smtp traffic from the web only goes to my mail server and that my mail server is the only machine on my local network that can send to the internet on port 25. This is t

  • Migrate to Lightroom 3 with tags

    I have been able to migrate the pics from Photoshop Album Starter Edition 3.2 into Lightroom 3 but for the life of me can't figure out how to bring the tags across. Am I missing something simple .... Any suggestions would be greatly appreciated