Thread: Help me PlZ

  1. #1
    Registered User
    Join Date
    Oct 2010
    Posts
    2

    Help me PlZ

    1- Write a function noDuplicates that insert an item but before inserting the item it checks whether the item is already in the list. If the item to be inserted is already in the list, the function outputs an appropriate error message.
    2- write a function that returns the info of the kth element of the linked list. If no such element exists, output an appropriate message.

    by using link list
    Last edited by UOB; 10-30-2010 at 11:07 AM.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    What have you tried?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Oct 2010
    Posts
    2
    Code:
    for the first function i tried this
    
    template<class Type>
    void linkedListType<Type>::noDuplicates(Type elem)
    {
         nodeType<Type> *cur;
         bool found=false;
         while (cur !=NULL)
         {
         if (cur->info ==elem)
    		 found=true;
    	 else
         cur=cur->link;
         }
         if (found)
         cout<<"Item you are trying to insert is already in the list";
         else
         insertLast(elem);
    
         }
    
    
    
    
    
    the second function 
    
    i didnt understand what they want exactly !!!
    i think it's like retrieve function ,but i dont know how to write it by using linked list

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    It looks like you forgot to initialise cur to the head of the linked list, and then you should break out of the loop once a match is found. You also need to improve your indentation.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. project .... help plz plz plz
    By Hitchhik3R in forum C Programming
    Replies: 13
    Last Post: 10-24-2010, 02:07 PM
  2. can any1 plz make this assignment
    By jean in forum C Programming
    Replies: 17
    Last Post: 05-13-2009, 09:19 PM
  3. [Request] Need Help Plz
    By TylerD in forum Tech Board
    Replies: 4
    Last Post: 01-03-2009, 09:54 AM
  4. Anyone plz help me
    By Rose_Flowers in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 09-17-2003, 12:01 PM
  5. help plz plz
    By nsssn73 in forum C++ Programming
    Replies: 2
    Last Post: 06-03-2002, 08:44 AM