Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added a display function to linked list algorithms. #137

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions src/data_structures/linked_list.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,33 @@ class LinkedList {
node = node.next;
}
}

/**
* Displays the full linked list in the terminal when run.
* You can append this function to other functions for an easier to read display.
*/
display(){
var runner = this.head;
var str = ''
while(runner!=null){
str += runner.val + " "
runner = runner.next
}
return str
}

/**
* removeFront() takes the head off the node, but still prevserves all subsequent nodes. Effectively moves the head to the original head.next.
*/
removeFront(){
if(!this.head){
return null
}
this.head = this.head.next
return this.head
}
}


/**
* A linked list node
Expand Down