단일 연결 리스트 Singly Linked Lists

KoEunseo·2022년 9월 20일
0

algorithm

목록 보기
5/8

index로 접근할 수 없다.
다음 데이터에 대한 정보를 통해 접근 가능하다.
각 노드는 단지 다음 노드를 가리킬 뿐이다.

Head--------------------------------Tail
[4] =next=> [6] =next=> [8] =next=> [2] =null=>

push

class Node{
    constructor(val){
        this.val = val;
        this.next = null;
    }
}
class SinglyLinkedList{
    constructor(){
        this.head = null;
        this.tail = null;
        this.length = 0;
    }
    push(val){
        var newNode = new Node(val);
        if(!this.head){
            this.head = newNode;
            this.tail = this.head;
        } else {
            this.tail.next = newNode;
            this.tail = newNode;
        }
        this.length++;
        return this;
    }
}
var list = new SinglyLinkedList()
profile
주니어 플러터 개발자의 고군분투기

0개의 댓글