Thread: Linked lists

  1. #1
    Registered User
    Join Date
    Jul 2008
    Posts
    72

    Linked lists

    I really need some who can show me how to do this. I'm getting deperate. I just can't get it to work

    That's the input in the text file and it includes the output (print). The output won't be in there, obviously.
    It's just like a "sentence editor" if you will.


    delete("is",2)
    print 1:This 2:is 3:an 4:an 5:icorrect 6:sntence
    delete("an",3)
    print 1:This 2:is 3:an 4:icorrect 5:sntence
    delete("icorrect",4)
    print 1:This 2:is 3:an 4:sntence
    insert("incorrect",4)
    print 1:This 2:is 3:an 4:incorrect 5:sntence
    delete("sntence",5)
    insert("sentence",5)
    print 1:This 2:is 3:an 4:incorrect 5:sentence
    neighbors("is") 2:is previous:This next:an
    So, to take the first line, it will put the delete("is",2) into the node and follow the command.

    So far I have..

    Code:
     class List {
         private:
                 Node data;
                 List *next;
    
    insert() {
        if (head == NULL) {
          // This is the first node.
        } else {
          // Subsequent nodes
        }
    }
    
    
    delete() {
            // Delete via the number here?
          
          //and loop here for the node
          prev->next = cur->next; //
    
         // Now, free() or delete the current node?
    }
    
    };
    I'm guessing that's how you do it. I don't know how to finish this. How to implement the delete, insert, and the loops. Not sure what to do with the print either.. needs to be put into another text file, but I'll see about that.

    Can somebody please show me how to do this? Thank you so much!! I hope somebody can help me here.
    Last edited by XodoX; 10-08-2010 at 09:04 PM.

  2. #2
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    You can't have a function called delete because delete is a C++ keyword.

    You could give it a capital D, but it would better to call it something like remove, which is closer to an antonym of insert anyway.

    Functions also need return types, even if it's just void.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  3. #3
    Registered User
    Join Date
    Jul 2008
    Posts
    72
    I don't know.

  4. #4
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    Quote Originally Posted by XodoX View Post
    I don't know.
    Huh. I hadn't even asked you a question. You don't know what?
    Have you done as I suggested? What further problems do you have?

    Give us something we can use to help you... Post some updated code or something. At the moment it sounds to me like you're really saying "I don't care".
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Dynamic Lists? Is it possible? Is it a logical solution?
    By arcaine01 in forum C++ Programming
    Replies: 10
    Last Post: 07-23-2009, 01:08 AM
  2. Question about Linked lists of lists
    By hear_no_evil in forum C Programming
    Replies: 2
    Last Post: 11-08-2004, 02:49 AM
  3. Linked Lists 101
    By The Brain in forum C++ Programming
    Replies: 5
    Last Post: 07-24-2004, 04:32 PM
  4. Map file formats and linked lists
    By Spitball in forum Game Programming
    Replies: 2
    Last Post: 03-04-2004, 11:32 PM
  5. need help w/ linked lists
    By MKashlev in forum C++ Programming
    Replies: 11
    Last Post: 08-05-2002, 08:57 PM