function LinkedList() {
let Node = function(element){ //(1)
this.element = element
this.next = null
}
let length = 0 //(2)
let head = null // (3)
this.append = function(element){
let node = new Node(), //(1)
current //(2)
if (head === null){ // 리스트가 비어있다면 // (3)
head = node
}else{
current = head //(4)
// 마지막 원소를 발견할 때까지 계속 루프 순환한다.
while(current.next){
current= current.next
}
// 마지막 원소를 링크할 수 있게 노드에 할당한다.
current.next = node
}
length++ // 리스트의 크기를 업데이트한다. (6)
}
this.removeAt = function(postion){
if(postion > -1 && postion < length){ //(1)
let current = head, //(2)
previous, //(3)
index= 0 //(4)
// 첫 원소 삭제
if(postion === 0){ //(5)
head = current.next
}else{
while(index++ < postion){ //(6)
previous = current //(7)
current = current.next //(8)
}
// 현재의 다음과 이전것을 연결한다: 삭제하기 위해 건너뛴다
previous.next = current.next //(9)
}
length-- //(10)
}else{
return null //(11)
}
}
this.remove = function(element){
let index = this.indexOf(element)
return this.removeAt(index)
}
this.indexOf = function(element){
let current = head, //(1)
index = -1


while(current){ //(2)
if(element === current.element){
return index //(3)
}
index++ //(4)
current = current.next //(5)
}
return -1
}
this.isEmpty = function() {
return length === 0
}
this.size = function() {
return length
}
this.toString = function() {
let current = head, //(1)
string = '' //(2)


while(current){ //(3)
string = current.element //(4)
current = current.next //(5)
}
return string //(6)
}
this.print = function() {
alert(this.toString());
}
}

let list = new LinkedList()

list.append(13)
list.print()
list.append(15)
list.print()

일케했는데 undefined 왜뜨지 ㅅㅂ


시발 ㅋㅋ append 부분에선 Node 받을때 element를 상속 안받으니까 append가 안되고

indexOf 부분 다시보니까 index를 -1로 정의해놔서 무조건 return -1 로 가고있엇음 ㅋㅋ 진짜 나 개빡통이넴