TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Guest User
Tech Writer
357
120.8k
Custom Doubly Linked List Implementation
Sep 12 2013 1:42 PM
Given the following code snippet, I need clarification on a Custom Doubly Linked List Implementation:-
I have placed comments under each line of code, please correct where necessary...
public void ReverseList()
{
CustomDoubleLinkedListItem<T> node = this.RootNode.NextNode;
// Get a reference to the current root nodes next node? what is this previously set to and how, constructor?
CustomDoubleLinkedListItem<T> previousNode;
// declare a field named previous node
CustomDoubleLinkedListItem<T> nextNode;
// declare a field named next node
while (node != null)
{
nextNode = node.PreviousNode;
// next node is set to reference the nodes previous node
previousNode = node.NextNode;
// previous node is set to reference the nodes next node
node.PreviousNode = previousNode;
// the nodes previous node is set to reference the previous node
node.NextNode = nextNode;
// the nodes next node is set to reference the next node
//Handle the old root? what is meant by old root?
if (previousNode == null)
{
previousNode = this.RootNode.NextNode;
// previous node is set to reference the current root nodes next node
this.RootNode.NextNode = null;
// current root nodes next node is set to reference null
this.RootNode.PreviousNode = previousNode;
// set the root nodes previous node to reference the previous node
this.RootNode = node;
// set the current root node to reference the node, which node? old or current?
previousNode = null;
}
if (previousNode == this.RootNode)
{
node.PreviousNode = null;
}
node = previousNode;
}
// Not sure the whole logic of the above comparsion\equality?
}
Thanks
Reply
Answers (
4
)
Suggest for upload file and obtain link to download
Windows store APPs Development in VS 2012 (windows 8)