Help me with linkedlist please!!

public void insert(int id, int inv)
Object value = new Item (id, inv);
DoublyListNode temp = new DoublyListNode(null, value, null);
if (size == 0)
addLast(value);
else
DoublyListNode p = first;
while ((p != null) && (((Item)p.getValue()).compareTo(value)) > 0)
p = p.getNext();
if (((Item)first.getValue()).compareTo(value) > 0)
addLast(value);
else
if (((Item)first.getValue()).compareTo(value) < 0)
temp.setPrev(last);
last.setNext(temp);
last = temp;
size++;
else
DoublyListNode tempPtr = first;
while (((Item)tempPtr.getNext().getValue()).compareTo(value) < 0)
tempPtr = tempPtr.getNext();
temp.setPrev(tempPtr);
temp.setNext(tempPtr.getNext());
tempPtr.setNext(temp);
temp.getNext().setPrev(temp);
size++;
why is my insertion method does the same thing as the addLast?
the list is in it's original order..

Singly linked list implementation using a dummy head. I haven't implemented a delete method, I'll leave that up to you :)
public class Test {
    public static void main (String[] parameters) {
        LinkedList list = new LinkedList ();
        list.add ("0");
        list.add ("2");
        list.insert ("1", 1);
        System.out.println (list);
    private static class LinkedList {
        private Node head;
        private int size;
        public LinkedList () {
            head = new Node (null); // dummy
            size = 0;
        public boolean isEmpty () {
            return head.getNext () == null;
        public void clear () {
            head.setNext (null);
        public void add (Object value) {
            insert (value, size);
        public void insert (Object value, int index) {
            Node node = getNode (index - 1);
            node.setNext (new Node (value, node.getNext ()));
            size ++;
        public Object get (int index) {
            return getNode (index).getValue ();
        /* note that index can be -1: that's the (dummy) head */
        private Node getNode (int index) {
            if (index < -1 || index >= size) {
                throw new IndexOutOfBoundsException ();
            Node node = head;
            int i = -1;
            while (i < index) {
                node = node.getNext ();
                i ++;
            return node;
        public String toString () {
            return isEmpty () ? "" : head.getNext ().toString ();
        private class Node {
            private Object value;
            private Node next;
            public Node (Object value) {
                this (value, null);
            public Node (Object value, Node next) {
                this.value = value;
                this.next = next;
            public Object getValue () {
                return value;
            public void setNext (Node next) {
                this.next = next;
            public Node getNext () {
                return next;
            public String toString () {
                return value + ((next == null) ? "" : ", " + next);
}Hope this helps.

Similar Messages

  • TS3276 I am not able to Mobile Me email account to connect with iCloud or my Apple Mail program. Don't know if my settings are correct or not. Can anyone help me with this please?

    I am not able to Mobile Me email account to connect with iCloud or my Apple Mail program. Don't know if my settings are correct or not. Can anyone help me with this please?

    http://support.apple.com/kb/HT5922
    If you want to mirror your desktop, see:
    http://support.apple.com/kb/HT5404
    Regards.

  • I have a brand new MacBookProo and I can not open PDF files from my desktop. Can anyone help me with this please?

    I have a brand new MacBookProo and I can not open PDF files from my desktop. Can anyone help me with this please?

    A new Mac comes with 90 days of free tech support from AppleCare.
    AppleCare: 1-800-275-2273

  • Can anyone help me with forms please

    -----------------------------------source.cfm--------------------------------------------
    <cfquery name="myquery" datasaource="mydatasource">
    select studentid
    from tbl_student
    </cfquery>
    <cfform action="reciever.cfm" method="post">
    <cfoutput query="myquery">
    <cfinput name="#myquery.studentid#" type="text">
    </cfoutput>
    </cfform>
    ------------------------------------reciever.cfm------------------------------------------ ----
    <cfquery name="myquery2" datasource="mydatasource">
    select studentid,studentname
    from tbl_student
    </cfquery>
    <cfoutput query="myquery2">
    <cfif #form.#myquery2.studentid## eq
    #myquery2.studentname#>
    Student Found
    </cfif>
    </cfoutput>
    anyone can know how to do this? i just want to make the
    #form.# dynamic because the id is coming from database
    but seems it is not allowed... anyone can help me with this
    please?or anyone know alternative solution for it?thanks in
    advance.

    thanks again cf_dev2...
    but the <cfinput> that i'm trying to use was dynamic
    because it can be a textbox or a radio button or a checkbox.. i got
    no problem in assigning their name now.. because i string
    concatinated them like placing their specific id from the database
    into their name,for example
    <cfquery name="choices" datasource="mydatasource">
    select choiceid,choicetype
    from tbl_choice
    </cfquery>
    <cfform name="source.cfm" method="post">
    <cfoutput query="choices">
    <cfset choicename='multiplechoice'>
    <cfset choicenamed = choicename.concat(#choiceid#)>
    <cfif #choices.choicetype# eq 'multiplechoice'>
    <cfinput type="radiobutton" name="#choicenamed#">
    </cfif>
    </cfoutput>
    </cfform>
    the problem now is the way how can i receive it and compare
    it on the answer values from the database for the choices.

  • HT5622 i need help using the icloud it is not making any since to me can some one call me and help me with it please don't try to help me through email i need to talk and listen i don't understand instruction by reading

    i need help using the icloud it is not making any since to me can some one call me and help me with it please don't try to help me through email i need to talk and listen i don't understand instruction by reading.
    <Phone Number Edited by Host>

    You aren't addressing anyone from Apple here.  This is a user forum.
    You might want to call a neaby Apple store to see if they have a free class you could attend.

  • Help me with JARs PLEASE!!!!

    Hello,
    Following is the scenario
    Application name: PL
    Directory "PL" has
    - A.jar
    - B.jar
    When I create PL.jar I store it in the dir "PL" by using the appropriate relative path to A.jar and B.jar in the manifest file. PL.jar executes in folder "PL"; BUT when I copy PL.jar to another folder say desktop it gives me a NoClassDefFoundError. Can anybody help me with this as I have wrecjed my brains over this for 2 days. I have to distribute PL.jar to clients for testing purpose.....Please reply ASAP.
    Thanks.
    Salil.

    set (class) path or use package if its inside your dir.
    Message was edited by:
    deAppel

  • Suddenly my music videos won't play on my iPad. I just get the audio? Can anyone help me with this please?

    SUddenly my music videos won't play on my ipad1. I just get the audio. Can anyone help with this please?

    Look in the Videos App and play them in there.

  • Hi, my name is Chenet i have a Macbook 0sx lion 10.7.5 i don't remember my password for the system preferences i can't even go online, can somebody help me with that please

    Hi, my name is Chenet i have a Macbook 0sx lion 10.7.5 i don't remember my password for the system preferences i can't even go online, can somebody help me with that please

    Hi 'baltwo'
    Thank you for your link, I already had been on this particular website this afternoon. they only discuss problems in the application and nothing about how the MS Office application installation does disturb Mac OS.
    Or have I missed a special comment there?
    In any case many thanks, trioloGo

  • Help needed with JDBC - please help! (newbie)

    hi all
    i m new to jdbc
    i have installed MySQL server on my winxp machine
    i used the command:
    mysql -p -u root
    Enter password: ****now when writing a prog i m getting a prob at this piece of code:
    Connection con=DriverManager.getConnection("jdbc:odbc:books","root","root");wot is wrong wid this code?
    please help......
    thanks in advance

    There are about 20 different things that could be wrong a this point; I'm not going to list them all. If you want specific help, you need to post specific information. This is usually done by posting either a stack trace from an exception, or a more complete section of code and a description of the problem and ALL the symptoms. You have all the information on what you've done, we have none of it.
    Instead of trying to diagnose whats wrong with your ODBC setup, I'm going to give you some strong advice; don't use ODBC with JDBC if you can avoid it, and with MySQL you can avoid it. It makes things simpler, less can go wrong, and you don't have to configure a DSN on every machine that you install the program on.
    To use "pure" JDBC without ODBC for MySQl:
    1) download the JDBC driver (you might already have this)
    http://dev.mysql.com/downloads/connector/j/3.1.html
    2) follow the installation instructions
    http://dev.mysql.com/doc/refman/5.0/en/java-connector.html
    In particular, make sure your classpath is set correctly
    3) Here's an example of loading the driver and establishing a connection
    http://dev.mysql.com/doc/refman/5.0/en/cj-connect-with-drivermanager.html
    Note the form of the connection URL,
    "jdbc:mysql://localhost/test?user=monty&password=greatsqldb"
    This is what an URL without ODBC looks like; there is no DSN, which means no DSN has to be configured.
    4) The MySQL database has some built-in security, to prevent malicious connections from outside computers. Solutions to that and other common problems are here:
    http://dev.mysql.com/doc/refman/5.0/en/cj-faq.html

  • Help me with net, please!!!

    I'm a beginner
    I have to learn java urgently... as fast as possible.
    So I need a little net. application which works with strings, url and have graphic interface?
    For example: a window with button, which on pushing get some information from one of the url and do something with this information. It doesn't matter...
    Have you smth for me???
    Please!!!

    public class TeachmeJava{
    boolean lazy = true;
    String solution="Study!!!!!";
    public static void main (String args){
    TeachmeJava j = new TeachmeJava();
    if (j.lazy){
    System.out,println(solution);
    Does this help? ;)
    Sorry for the typo. Too many custom tags lately :)

  • System now workin :) help/advice with XP please if you can

    finally got my new system to post so looking good sp far...... started installing win xp and had an error message - disc might be a dodge one!! then thought 'o sod it, i think i'll use win 2000 anyway as seems to have less probs than xp at the mo'
    the problem is, as the install didnt complete, each time i put my win2000 cd in the drive it tries to finish the xp installation. i cant seem to get it to boot from the win2000 disc.
    how do i stop win xp doing this?? can you 'back-it-out' some how or shouldnt it do this and the win2000 should 'take-over'
    bit confused on what to do.
    hope someone can help.
    thanx

    Hi
    Your first problem with XP not completing does sound like a bad disc or your rom drive. Can you borrow another CD or Rom Dive. Can you make a copy of your XP CD on another machine and try the copy.
    Whether you stick with XP or go to Win2000 I suggest you delete partion, reformat and start again. If you are a games player do not move over to Win2000.
    Best of Luck. Russ Pyne

  • Presentation with animation, can somebody help me with that, please?

    Hi,
    I'm looking for a software wich contains some nice animations and allows me to create different presentations. Does anybody has any suggestion? Final Cut maybe? Or Adobe After Effects? And is really truth that the student version of Final Cut doesn't allow you to upgrade? A lot of questions, but hopefully I'll get some help.
    Thanks!
    MacBook Pro 2.0Gig   Mac OS X (10.4.7)  

    I'm looking for a software wich contains some nice animations<<</div>
    What kind of animations? Are you taking about animated motion backgrounds? Text animations? Or animations as in "cartoons"? Please be more specific.
    And yes, FCP's academic version has never been upgradable until the recent crossgrade offer: www.apple.com/universal/crossgrade
    -DH

  • Any one help me with Links please!

    For my links to work I have to click it twice.
    For some reason when I move my cursor over my web page
    a box appears around the whole page and my cursor turns into
    a
    hand indicating that the whole page is a link.
    Can anyone help me.
    Thanks.

    That question comes up daily on these forums. It has to do
    with Active Content and Internet Explorer.
    Here's a page that will give you everything you need to deal
    with this little annoyance:
    http://www.adobe.com/devnet/activecontent/

  • HT1212 Help me with this please.

    I forgot my iPhone 4S passcode, and it says "connect to iTunes" I have connected to Itunes, and what comes up is "Itunes cannot connect to (name of phone) because you need to enter your passcode! Someone please help me, as it is really irritating.

    Try reading the whole article on which you've referenced.

  • HELP ME WITH CHAT PLEASE (IM BEGGING YOU)

    I have been searching for chat for hours. I wanted to call customer support initially to ask this question, but they said that they no longer answer questions about Creative Suite. They told me to ask a question in chat or in a forum. I didn't want to ask a forum because that usually takes too long, but I cant find chat, and again, I have been looking for hours. I just wanted to know if I bought Creative Suite 5.5, how much would it take to update it to 6? I've just been sent to loop after loop and there has been no attempt to help me. I'm sorry, I'm a little angry right now, but I really just want my questions answered in a timely manner. So, I actually have two questions. How much does it take to update CS 5.5 to CS 6? Where is chat because I have not been able to find it for hours? And before anyone says anything about Creative Cloud, NO, I am not interested, it costs too much for me or any freelance artist, and I find the whole thing to be kind of a mean thing to do, it just milks more and more money out of people who just want to improve or meet job requirements. Please help me and thank you if you do. Have a nice day, everybody!
    P.S Sorry this is in the wrong category, but I could not find a Creative Suite option.

    How much to upgrade to CS6?  Easy question.
    Creative Suite 6
    Click on "Buy" for your suite and from the drop down menu, "upgrade"
    Click on "Select" to go to your cart. Click on Edit if you want to change that upgrade from Windows to Mac. (You must own Mac CS 5.5)

Maybe you are looking for

  • Custom Page Size list...can it be re-ordered?

    As a service provider I must get asked this question two or three times per week. I'm hoping someone has figured this out as it seems to be a pretty common complaint. When you create a new custom page size the new size gets added to the list in a com

  • IDOC_DATA_INSERT

    Hi all, I am trying to insert data to a new segment in COND_A idoc (outbound idoc) .To fill this segment , i need data from E1konh and Ekonp , the user exits are carrying only E1komg data. I found a badi IDOC_DATA_INSERT where i would get the require

  • How do I add cells using a LEN, Indirect formula?

    On a table called "Checkpoint" I have inserted the formula shown below in cell C3. It's purpose is to copy a value from a set of other tables (Day 1 - Day 31). On one of the "Day" tables is a cell e3 that contains the number 3. Using the formula show

  • Need Fm/BAPI to change Actual GR date(WADAT_IST_LA) in inbound delivery

    Hi , Need a function module/BAPi to change the Actual Goods Receipt date for inbound delivery . Any suggestion would be appreciated . Have tried with WS_DELIVERY_UPDATE and BAPI_INB_DELIVERY_CHANGE . Am I missing something here ? Regds, Sanjeev

  • Loosing connection with my xbox360

    Hi everyone, I just purchased a wrt160n router and I am wireless with my xbox360. While on xbox live playing an online game "cod4" I can't get through a game most of the time without loosing a connection, with the 54gs router I had there was not an i