View Single Post
Old 02-04-2007   #9
Dazlingo
Registered Member
 
Dazlingo's Avatar
 
Last Online: 12-13-2007
Join Date: Jan 2007
Posts: 51
Thanks: 0
Thanked 3 Times in 2 Posts
Groans: 0
Groaned at 0 Times in 0 Posts
Default Re: plzzz i need help in c++

lol, list chainee.... loooooooooooooooooooooooooooooooooooooool
man where the node is defined ???
anyway i am WITH Iceberg, but im too bored right now, so i thought id write smth up.
im not gonna comment the code (ba3ed na'is :P)

class definition
Code:
class node
{
private:
    node *next;
    int value;
public:
    node(){next=NULL;}
    node(int v){next=NULL;value=v;}
    void setNext(node *n){next=n;}
    node* getNext(){return next;}
    int getVal(){return value;}
    void setVal(int v){value=v;}
    void insertNode(int v)
    {
        node *p=this;
        while(p->getNext ()!=NULL)
            p=p->getNext();
        p->setNext(new node(v));
    }    
};
for the use of it:
how u can fill it
Code:
    node L1(5), L2(2);
    L1.insertNode (8);
    L1.insertNode (3);
    L1.insertNode (4);

    L2.insertNode (1);
    L2.insertNode (6);
    L2.insertNode (7);
do the addittion:

Code:
    node L3;
    node *t1=&L1;
    node *t2=&L2;
    node *t3=&L3;

    for (int i=0;i<4;i++)
    {
        t3->setVal (t1->getVal () + t2->getVal ());
        t3->setNext (new node);
        t3=t3->getNext ();
        t1=t1->getNext ();
        t2=t2->getNext ();
    }
and finally the print:

Code:
    t3=&L3;
    for (i=0;i<4;i++)
    {
        cout << "Value " << i << " : " << t3->getVal () << endl;
        t3=t3->getNext ();
    }
im just in a good mood today, so i wrote this thingy. it's working


AND LEARN TO DEBUG !!!!!! u wont go far without it

edit: you need the double ? go do it :P should be REALLY easy with the code above.

Last edited by Jean; 02-04-2007 at 05:32 PM. Reason: bad words are not allowed
Dazlingo is offline   Reply With Quote