CSC235 Data Structures - List Homework
-
Given the following picture of a linked list, where P and Q are of
type ptrType:
Write the code that will manipulate the linked list as follows.
Each question should use the original list shown above.
- Make P point to the node containing the number 10.
- Make Q point to the node containing the number 8.
- Make P point to the node containing the number 6.
- Make the node containing the number 8 point to the node containing
the number 6.
- Make the node containing the number 10 point to the node containing
the number 8.
- Make the node containing the number 6 point to the node containing
the number 10.
- Add the Item field in the node P points to and the Item field in
the node Q points to and store the result in the node that currently
contains 10.
- Remove the node containing 12 from the list.
-
Given the following linked list, where P, Q and S are of type ptrType:
Show how each of the following statements changes the linked list.
Draw a similar diagram and show the resulting list. Each question should
be answered starting with the original list shown above.
- S->Item = P->Item;
- P->Item = Head->Item + Q->Item;
- S = Q->Next;
- P->Next = Head;
- Head->Next = Q->Next;
- Q->Next = S->Next;
- Q = Q->Next;
- P->Next = P;
-
Write a member function called traverse in the unordered list class
that prints out the contents of each node in the list. If the list is
empty, print the message "empty list".
-
Write a member function called last in the unordered list class
that returns the item in the last node of the list.
-
Write a member function called makeRev that has one parm, an unordered
list, which sets the parm to contain the same values as the invoking
object, but in the opposite order.
-
Use the unordered list methods to write the statements to delete
every other node in the list called mylist, starting with the first node.
-
Suppose the value 10 might be in the list mylist more than once. Use the
unordered
list methods to write the statements to delete all occurrences of the
value 10 from the list.
-
Use the unordered list methods to write the statements to create a list
called revlist that contains the same values as the list mylist, but in
the opposite order.
-
Suppose p, q, and r are declared as type node*. Show what is printed
for each of the following, or explain why an error occurs:
a. p = new node; b. p = new node;
p->Item = 3; p->Next = new node;
q = new node; q = p->Next;
q->Item = 7; q->Next = NULL;
q->Next = p; p->Item = 5;
p = new node; q->Item = 10;
p->Item = q->Item; r = new node;
cout << p->Item << q->Item << q->Next = r;
q->Next->Item << endl; q->Item = r->Item;
r->Item = p->Item + 1;
cout << r->Item <<
q->Item << p->Item << endl;
Email Me |
Office Hours |
My Home Page |
Department Home |
MCC Home Page