about Linked List

Tue, Feb 16, 2021 One-minute read

CRUD and linked list algorithm in real life

CRUD, we as junior-level SEDs, just cannot escape from it.

and understand data structures can really operate CRUD in an much effciently way.

[real-life-CRUD]

  • keep add the cards into a linked list, without considering it’s id order.
image

linked list CRUD

image

linked list CRUD

  • but in real life, once you add a card to it, it need reorder according to its id order.
image

linked list CRUD

image

linked list CRUD

image

linked list CRUD

The way to traverse

data structures

  • linear

    • for / while iteration

  • nonlinear

    • recursion

Array traversal

  • linear iterative

Linked list traversal

  • linear iterative

  • recursive structure

Binary tree traversal

  • nonlinear

Q1: HOW TO REVERSE A LINKED LIST

public ListNode reverseLinkedList(ListNode head) {
    ListNode prev = null;
    while (head != null) P{
    }
}

public ListNode  reverse(ListNode head) {
   // base case 
   ListNode newHead = reverse(head.next);
   head.next.hext = hed;
   return newHead;
}

Q2: HOW TO REVERSE N nodes in A LINKED LIST

public ListNode  reverse(ListNode head, int n) {

}

DP