COM1201 Spring 1997 - Professor Fell - Quiz 1


Thursday, April 3, 1997

Problem 1: Assume the following declarations:

struct Node {
	char data;
	Node* next;
};

Node* list;
And that the following linked list has been created: Picture of a linked list of char saying FEDCBA

For each of the following code segments start with this list and, draw a NEAT picture showing the resulting list(s), any unreferenced nodes, and where the pointers list and p point.
// a. Change List 1

	for (Node* p = list; p != NULL; p = p->next)
		if (p->data == 'C')
			if (p->next != NULL)
				p->next = p->next->next;

// b. Change List 2
	for (Node* p = list; p != NULL; p = p->next)
		if (p->next != NULL)
			p->next = p->next->next;

// c. Change List 3
	for (Node* p = list; p != NULL; p = p->next)
		if (p->data == 'A' || p->data == 'E')
			p->data = '*';				

Problem 2: Write a code segment that will change the data field of every node but the last one in list list to a 'Z'. (So list: FEDCBA becomes list ZZZZZA)


Last Updated: April 6, 1997 11:46 pm by

Harriet Fell
College of Computer Science, Northeastern University
360 Huntington Avenue #161CN,
Boston, MA 02115
Internet: fell@ccs.neu.edu
Phone: (617) 373-2198 / Fax: (617) 373-5121
The URL for this document is: http://www.ccs.neu.edu/home/fell/COM1101/QUIZ/Q1/quiz1.html