Answers to Selected Exercises Chapter 1



Download 0.49 Mb.
Page4/7
Date18.07.2017
Size0.49 Mb.
#23634
1   2   3   4   5   6   7

Chapter 6


3. Member functions Enqueue and Dequeue would have to be changed.

6. No, the class definition would not have to be changed. Only the definition of NodeType would have to be changed.

9. Write a member function Copy of the Stack ADT, assuming that self is copied into the stack named in the parameter list.

template

void StackType::Copy(StackType& anotherStack)

{

NodeType* ptr1;



NodeType* ptr2;

if (topPtr == NULL)

anotherStack.topPtr = NULL;

else


{

anotherStack.topPtr = new NodeType;

anotherStack.topPtr->info = topPtr->info;

ptr1 = topPtr->next;

ptr2 = anotherStack.topPtr;

while (ptr1 != NULL)

{

ptr2->next = new NodeType;



ptr2 = ptr2->next;

ptr2->info = ptr1->info;

ptr1 = ptr1->next;

}

ptr2->next = NULL;



}

}

12. (a) Doubly linked



(b) Circular

(c) List with header and trailer

15. (b)

(c)





free

3







list

1







nodes







.info

.next

.back

[0]

17

2

1




[1]

4

0

NUL




[2]

25

NUL

0




[3]













[4]













[5]













[6]













[7]













[8]













[9]













(d)




free

0







list

1







nodes







.info

.next

.back

[0]

17

3

1




[1]

4

2

NUL




[2]

25

NUL

1




[3]













[4]













[5]













[6]













[7]













[8]













[9]












17. Static binding is the determination of which function to call at compile time; dynamic binding is the determination of which function to call at run tim




Download 0.49 Mb.

Share with your friends:
1   2   3   4   5   6   7




The database is protected by copyright ©ininet.org 2024
send message

    Main page