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

where is reverse a linked list methodology? #36

Open
akash5324 opened this issue Oct 4, 2018 · 1 comment
Open

where is reverse a linked list methodology? #36

akash5324 opened this issue Oct 4, 2018 · 1 comment

Comments

@akash5324
Copy link

No description provided.

@anuragarwalkar
Copy link

https://www.geeksforgeeks.org/reverse-a-linked-list/

reverse() {
if (this.head) {
// p n c
// null 1, 2, 3, 4, 5 null

  let current = null;
  let previous = null;
  let node = this.head;

  while (node) {
    current = node;
    node = node.next;
    current.next = previous;
    previous = current;
  }

  return previous;
}

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants