Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
31 |
Tags
- 프로그래머스
- 항해99
- 자바 for문
- 자바 public
- 자바 자동캐스팅
- 자바 while문
- 이클립스 DB연동
- 변수
- 자바 조건문
- 정보처리기사실기
- 조코딩
- 자바 구구단 출력
- 자바 향상된 for문
- 자바 스캐너
- Til
- TypeScript
- 자바 강제 캐스팅
- 자바 반복문
- 항해99 2기
- Vue3
- react ag grid
- MySQL
- react with typescript
- 자바 if문
- 자바
- 자바 삼항연산자
- 타입스크립트
- 자바 공배수
- 자바 switch문
- java
Archives
- Today
- Total
뇌 채우기 공간
[알고리즘] 링크드리스트 print_all구현 본문
class Node:
def __init__(self, data):
self.data = data
self.next = None
node = Node(3)
first_node = Node(4)
node.next = first_node
print(node.next.data)
class LinkedList:
def __init__(self, data):
self.head = Node(data)
def append(self, data):
if self.head is None:
self.head = Node(data)
return
cur = self.head
while cur.next is not None:
cur = cur.next
cur.next = Node(data)
def print_all(self):
cur = self.head
while cur is not None:
print(cur.data)
cur = cur.next
print('여기')
linked_list = LinkedList(3)
linked_list.append(4)
linked_list.append(5)
linked_list.append(6)
linked_list.print_all()
cur변수에 head를 넣고 끝까지 돌면서 cur을 프린트하는데
cur을 하나씩 next로 간다
728x90
'알고리즘' 카테고리의 다른 글
[알고리즘] 링크드리스트 delete_node구현 (0) | 2021.06.13 |
---|---|
[알고리즘] 더하기 or 곱하기 python (0) | 2021.06.12 |
[알고리즘] 시간 복잡도 판단하기 (0) | 2021.06.12 |