3 Replies - 598 Views - Last Post: 29 May 2008 - 06:37 AM Rate Topic: -----

#1 sid2008  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 01-April 08

need help in this question

Post icon  Posted 28 May 2008 - 02:40 PM

hi everyone..I had a test today and one thing which i could not answer of this question..this is given .

typedef int elementType;

class node1{
friend class list1;
private:
elementType data;
node1 * next;
};

class node2{
friend class list2;
private:
elementType data;
node2 * next;
node2 * prev;
};

class list1 {
public:
list1() {first =NULL;}//constructor
. . . //other member functions

private:
node1 * first;
};


class list2 {
public:
list2() {first =NULL;}//constructor
. . . //other member functions

private:
node2 * first;

};
question is..

1. Consider the following code in a member function of the list1 class. Draw the linked list that is the result of executing the following code.

node1 * q = new node1;
first = new node1;
first->data = 33;
q->data =44;
node1 * p = new node1;
p->data = 55;
p->next = q;
q->next = first;
q = new node1;
q->data =45;
q->next = NULL;
first->next = q;
first = p;

plz let me know if anyone knows its answer..

Is This A Good Question/Topic? 0
  • +

Replies To: need help in this question

#2 KYA  Icon User is offline

  • g++ jameson.cpp -o beverage
  • member icon

Reputation: 3089
  • View blog
  • Posts: 19,136
  • Joined: 14-September 07

Re: need help in this question

Posted 29 May 2008 - 03:12 AM

Seems like its more of a pointer manipulation question then a linked list one.

pointer q points to a new node: node1

first is a new node as well

the data of first is set to 33

q is set to 44

so on and so forth....I was wondering .... if the test is already over why do you need this? Won't it be given you in a review of the material afterwards?
Was This Post Helpful? 0
  • +
  • -

#3 AmitTheInfinity  Icon User is offline

  • C Surfing ∞
  • member icon

Reputation: 109
  • View blog
  • Posts: 1,530
  • Joined: 25-January 07

Re: need help in this question

Posted 29 May 2008 - 03:23 AM

-------- -------- -------- --------
| 55 | -> | 44 | -> | 33 | -> | 45 | -> NULL
-------- -------- -------- --------


This is the way your list will look.
Was This Post Helpful? 0
  • +
  • -

#4 sid2008  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 01-April 08

Re: need help in this question

Posted 29 May 2008 - 06:37 AM

View PostAmitTheInfinity, on 29 May, 2008 - 03:23 AM, said:

-------- -------- -------- --------
| 55 | -> | 44 | -> | 33 | -> | 45 | -> NULL
-------- -------- -------- --------


This is the way your list will look.

HI...Thanks..thank you very much 4 ur help.
ya there is no need for me to know ans bec exam was over but the problem is i am taking one more course in next sem which is base on Data structure so i can atlest know that why did my ans wrong in test?so just 4 and there was final exam so noone will come 4 reviewing ur test thatsway i posted here....

Thanks agian.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1