Tuesday, February 16, 2010

01/14 : Reverse single list

 

 

Node

{

data;

Node * next;

}

 

List

{

int size,

Node * root;

}

 

 

ReverseList( List*  list)

 

{

// need to remember next pointer and previous poniter

Node * previous=null;

Node *next=list->root->next;

while(next!=null)

{

 

node *current=next;

// update next

next=next->next;

current->next=previous

//update previous

previous=current;

}

 

 

 

 

 

}

0 Comments:

Post a Comment

<< Home