how can we make class with Linked list recursion ...

Posted by epsilon_G on Stack Overflow See other posts from Stack Overflow or by epsilon_G
Published on 2010-03-29T16:13:24Z Indexed on 2010/03/29 16:23 UTC
Read the original article Hit count: 262

Hi , I'm newbee in The C++ heaven and the OOP, ... I'd like to make some stuffs with the Data structures ... However,I'd like to merge two linked listes ... I made a class before "List" wich contain all what I need to programme something with List ... Add , Display .. The probleme is that I programmed the function "Merge2lists" which give us the third list .. How can I display the third list in the main program after using "Merge2lists"

Plz , my prob with the Class and the OOP syntaxe ... try to give me the implementation in the main program ??? Otherwise,How can I apply function given pointer in main program wich declared in class .. Thankx

class Liste
{
     private:

             struct node
         {
              int elem ;
            node *next;
         }*p;


   public:
            LLC();
         void Merge2lists (node* a, node * b,node *&result);
         ~LLC();
};

void List::Merge2lists (node* a, node * b,node *&result)
 {

result = NULL;
if (a==NULL)
{ result=b;
    return;}

else if (b==NULL)
{ result=a;
    return;}

if (a->elem <= b->elem)
{
result = a;
 Merge2lists(a->next, b,result->next);
}
else {
result = b;
Merge2lists(a, b->next,result->next);
}
return;
}


int main()
{
   liste a ; 


   a.Aff_Val(46);
   a.Aff_Val(54);

   a.add_as_first(2);
   a.add_as_first(1);

   a.Display(); /*This to displat the elemnts ... Don't care about it it's easy to make*/

list liste2;
   b.Add(2);
   b.Add(14);
   b.Add(16);

list result;

     Merge2lists (a,b,result); /*The probleme is here , how can I use this in my program */

© Stack Overflow or respective owner

Related posts about c++

Related posts about algorithm