Thread: please debug the following code....

  1. #1
    Registered User
    Join Date
    Aug 2012
    Posts
    77

    Post please debug the following code....

    Was trying to implement a simple linked list program using c++ with only insert and display operations.There was no problem during compile time...the result was absent

    Compiler Used:

    DEV C++ 4.9.9.2

    Code:
    #include <iostream>#include <conio.h>
    #include <process.h>
    
    
    using namespace std;
    
    
    class NODE 
    {
          friend class LINKEDLIST;//to make LINKEDLIST a friend of NODE
          //in order to access NODE
          //but NODE cant access LINKEDLIST
          private:
                  int DATA;
                  NODE *LINK;
          
    };
    class LINKEDLIST
    {
          private:
                  NODE *START;
          public:
                 LINKEDLIST(){START=NULL;}
                 LINKEDLIST &Insert(int x);     
                 void Display();        
                  
          };
    LINKEDLIST &LINKEDLIST::Insert(int x)
    {
               NODE *NEW= new NODE;
               NEW->DATA=x;
               NEW->LINK=START->LINK;
               START=NEW;
               return *this;
    }
    void LINKEDLIST::Display()
    {
         NODE *ptr=START;
         while(ptr!=NULL)
         {
                         cout<<ptr->DATA<<" "<<endl;
                         ptr=ptr->LINK;
         }
    }
          
          int main()
          {
              LINKEDLIST L;
              L.Insert(45);
              L.Insert(78);
              L.Insert(10);
              L.Insert(99);
              L.Insert(16);
              L.Display();
              getch();
              return 0;
              }

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Code:
     NEW->LINK=START->LINK;
    If START is still NULL (ie you're inserting the first element), you are in big trouble here.

  3. #3
    Registered User
    Join Date
    Aug 2012
    Posts
    77
    thank you very much I have already got that ...thanks for responding

  4. #4
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    2,738
    Should I mention that you should use a newer IDE? If you'd like to keep the feel of DevC++, consider using Orwell Dev-C++
    Devoted my life to programming...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help debug palindrome code
    By mckinnley in forum C Programming
    Replies: 11
    Last Post: 01-02-2011, 11:00 AM
  2. Replies: 1
    Last Post: 03-10-2010, 11:28 AM
  3. Code:.Blocks debug ?
    By nobita in forum C++ Programming
    Replies: 6
    Last Post: 08-01-2009, 11:24 AM
  4. Help me debug this code
    By Blgihted in forum C Programming
    Replies: 4
    Last Post: 10-28-2005, 07:39 AM
  5. DEBUG code
    By myer_784 in forum C Programming
    Replies: 12
    Last Post: 03-15-2005, 11:45 PM

Tags for this Thread