Linked List deleting Help

This is a discussion on Linked List deleting Help within the C++ Programming forums, part of the General Programming Boards category; Hey all i am trying to delete a set number of items in a linked list. Here is the code ...

  1. #1
    Registered User
    Join Date
    Sep 2009
    Posts
    16

    Question Linked List deleting Help

    Hey all i am trying to delete a set number of items in a linked list. Here is the code for delete my item.
    Code:
    void unorderedLinkedList<Type>::deleteNode(const Type& deleteItem)
    {
    	nodeType<Type> *current; //pointer to traverse the list
    	nodeType<Type> *trailCurrent; //pointer just before current
    	bool found;
    	
    	found = false;
    			trailCurrent = first;  //set trailCurrent to point
    								   //to the first node
    			current = first->link; //set current to point to 
    								   //the second node
    
    			while (current != NULL && !found)
    			{
    				if (current->info != deleteItem) 
    				{
    					trailCurrent = current;
    					current = current-> link;
    				}
    				else
    					found = true;
    			}//end while
    
    			if (found) //Case 3; if found, delete the node
    			{
    				trailCurrent->link = current->link;
    				count--;
    
    				if (last == current)   //node to be deleted 
    									   //was the last node
    					last = trailCurrent; //update the value 
    										 //of last
    				delete current;  //delete the node from the list
    			}
    			else
    				cout << "The item to be deleted is not in "
    					 << "the list." << endl;
    		}//end else
    }//end deleteNode
    Right now it only deletes the 1 string i pass to it "deleteItem". However, i wish to delete the next 8 blocks after the "deleteItem".

    Say i have this in the list right now.
    bob barker is pretty old but still seems to get all the ladies
    Now the user would pick "bob" and with the code above, would delete "bob" but leave everything else. I wish to take out "bob, barker, is, pretty, old, but, still, seems, to" when the code above executes.

    Like so:
    bob (delete)
    barker (delete)
    is (delete)
    pretty (delete)
    old (delete)
    but (delete)
    still (delete)
    seems (delete)
    to (delete)
    get
    all
    the
    ladies
    I'm unsure on how to go about doing that. Any help would be great!

    David
    Attached Files Attached Files
    Last edited by StealthRT; 10-19-2009 at 09:31 PM.

  2. #2
    a_capitalist_story
    Join Date
    Dec 2007
    Posts
    2,651
    See also here, here, and here.

  3. #3
    Registered User
    Join Date
    Sep 2009
    Posts
    16
    Quote Originally Posted by rags_to_riches View Post
    See also here, here, and here.
    Helps a lot there. I came here to post the same since i wasent getting enough help from any other ones that i understood.

    David

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Quote Originally Posted by StealthRT View Post
    Helps a lot there. I came here to post the same since i wasent getting enough help from any other ones that i understood.

    David
    Yes but that means we have to go there and find out what it is that you don't understand, because we all enjoy reading three of the same threads to find out what you've already been told. Heaven forbid you actually tell us what you don't understand.

    (To be honest: I did read one of those threads (I don't know why), and I don't know that I can say anything that wasn't already pointed out there, namely (a) do you know how to count to 8? (b) do you know how to walk the list? (c) what if there's not 8 more elements on the list? (d) is it always supposed to be 8, or is that also variable?)

  5. #5
    a_capitalist_story
    Join Date
    Dec 2007
    Posts
    2,651
    Thank you, tabstop.

    See, that's exactly the point, StealthRT. Irrespective of what your parents instilled in you, you are not a special little snowflake to whose whims everyone must cater. Have some consideration for others who are providing their assistance to you FOR FREE.

  6. #6
    Registered User
    Join Date
    Sep 2009
    Posts
    16
    Alright, I’m done with this. If the only help I get is people who know how to do it and look down on those who do not then that is what the real time waster is and not that I try to post in a few forms and get different views from different people. There’s always more ways than 1 to code something. I may not get it for the first, second or third examples but maybe the forth one I do. I wouldn’t get that if I just settled on one forum for my question.

    You all need to get off your high pedestals and do what forums are meant to do in the first place-help people and not degrade them for asking questions that you would consider a no-brainer.

    To those who did help, thank you.

    David

  7. #7
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,307
    From what I can see, your failure to understand the advice that has been given to you already, indicates that you probably did not write the code posted, for if you could understand that, then you would surely have to understand some of the answers.

    If you're out of your depth, then you're pretty much going to drown. That's a fact of programming. The trick is to not end up in that situation in the first place. Throwing you a lifejacket wont help when you have no idea how to inflate it.
    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. Following CTools
    By EstateMatt in forum C Programming
    Replies: 5
    Last Post: 06-26-2008, 10:10 AM
  2. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM
  3. Problem with linked list ADT and incomplete structure
    By prawntoast in forum C Programming
    Replies: 1
    Last Post: 04-30-2005, 01:29 AM
  4. Linked List Help
    By CJ7Mudrover in forum C Programming
    Replies: 9
    Last Post: 03-10-2004, 09:33 PM
  5. singly linked list
    By clarinetster in forum C Programming
    Replies: 2
    Last Post: 08-26-2001, 10:21 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21