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..
need help in this question
Page 1 of 13 Replies - 534 Views - Last Post: 29 May 2008 - 06:37 AM
Replies To: need help in this question
#2
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?
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?
#3
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.
| 55 | -> | 44 | -> | 33 | -> | 45 | -> NULL
-------- -------- -------- --------
This is the way your list will look.
#4
Re: need help in this question
Posted 29 May 2008 - 06:37 AM
AmitTheInfinity, on 29 May, 2008 - 03:23 AM, said:
-------- -------- -------- --------
| 55 | -> | 44 | -> | 33 | -> | 45 | -> NULL
-------- -------- -------- --------
This is the way your list will look.
| 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.
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote




|