View Single Post
Old 11-09-2004, 10:11 PM   #1 (permalink)
if13121
Registered User
 
if13121's Avatar
 
Join Date: Oct 2004
Location: Bandung,Indonesia
Posts: 16
if13121 is on a distinguished road
Unhappy linked list problem

This is my list declaration
Code:
#define Nil NULL
#define info(P) (P)->info
#define next(P) (P)->next
#define First(L)((L).First)


typedef int infotype;
typedef struct tElmtlist *address;
typedef struct tElmtlist
{
	infotype info;
	address next;
}Elmtlist;


typedef struct
{
	address First;
}List;

i have this procedure:

void DeleteLast(List * L,infotype * X)
/*is : list not empty
 fs : last Element  list deleted. X save its value*/
{
	address Last,Prev;
	Last = First(*L);
	Prev = Nil;
	First(*L)=Last;
	while (next(Last) != Nil)
	{	Prev = Last;
		Last = next(Last);
	}
	*X = info(Last);
	next(Prev) = Nil;
}
 why if i changed the procedure become:

void DeleteLast(List * L,infotype * X)
{
	address Last;
	Last = First(*L);
	First(*L)=Last;
	while (next(Last) != Nil)
	{	Last = next(Last);
	}
	*X = info(Last);
	Last = Nil;
}
the procedure not work when i print all list element i still have last element

Last edited by Valmont; 11-10-2004 at 03:03 AM.
if13121 is offline   Reply With Quote