Help me PlZ

This is a discussion on Help me PlZ within the C++ Programming forums, part of the General Programming Boards category; 1- Write a function noDuplicates that insert an item but before inserting the item it checks whether the item is ...

  1. #1
    UOB
    UOB is offline
    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
    21,659
    What have you tried?
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    UOB
    UOB is offline
    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
    21,659
    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.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    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, 08: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

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