Welcome! Log In Create A New Profile



Posted by TIM 
Announcements Last Post
Announcement SoC Curricula 09/30/2017 01:08PM
Announcement Demarcation or scoping of examinations and assessment 02/13/2017 07:59AM
Announcement School of Computing Short Learning Programmes 11/24/2014 08:37AM
Announcement Unisa contact information 07/28/2011 01:28PM
April 05, 2006 11:19PM

Assignment one, Question five. Not sure of this question - must I create a list using a linked listforward as on page 285.

This is my solution. Am I doing it right, any corrections would be welcomed.
NB: - means dash with arrow as in txtbook

struct Adjective
string word;
Adjective * antonymPtr;
Adjective *current, *adjPtr;

adjPtr-word = "fat";
current = adjPtr;
current = current-antonymPtr;

current-word = "thin"
adjPtr-antonymPtr = current;
adjPtr = current-antonymPtr;
delete current;

Has any one done NO 9 and 13 on pages 211 and 213 respectively from chapter 3 and NO 14 on page 362 from chapter 5. My answers does not correspond with answers in txtbook. Any help really appreciate it.

Cheers guys
avatar Re: Unsure
April 06, 2006 10:13AM

Your system will crash.

ALWAYS check that the number of "delete"s is the same as the number of "new"s. You don't have any of the latter so you're trying to manipulate memory you haven't allocated yet.

Adjective *current = 0, *adjPtr = 0; // initialise pointers to null addresses

adjPtr = new Adjective; // allocate memory for first adjective object
adjPtr- >word = "fat";
// current = adjPtr- >antonymPtr; //don't do this, adjPtr- >antonymPtr doesn't point to anything yet

current = new Adjective; // allocate memory for the second adjective object
current- >antonymPtr = adjPtr; // link it back to the first object
current- >word = "thin"
adjPtr-antonymPtr = current; // add to end of first object

delete adjPtr- >antonymPtr; // deallocate memory from second object ("thin"winking smiley
delete adjPtr; // deallocate memory from first object ("fat"winking smiley
Anonymous User
Re: Unsure
April 08, 2006 10:39AM

i agree with Rob... thumbs up
cool smiley
Sorry, only registered users may post in this forum.

Click here to login