diff --git a/SOPTving/SOPTving/Presentation/MainScene/VC/MainVC.swift b/SOPTving/SOPTving/Presentation/MainScene/VC/MainVC.swift index b95600d..34eeb77 100644 --- a/SOPTving/SOPTving/Presentation/MainScene/VC/MainVC.swift +++ b/SOPTving/SOPTving/Presentation/MainScene/VC/MainVC.swift @@ -37,6 +37,17 @@ final class MainVC: UIViewController { return label }() + private lazy var prevButton = ButtonBuilder() + .setTitle("이전으로", + color: .white, + font: .tvingSemiBold(ofSize: 16)) + .setBackgroundColor(.systemBlue) + .setCornerRadius(12) + .setAction { [weak self] _ in + self?.prevButtonDidTap() + } + .build() + private lazy var nextButton = ButtonBuilder() .setTitle("다음으로", color: .white, @@ -48,6 +59,7 @@ final class MainVC: UIViewController { } .build() + //MARK: - Life Cycle override func viewDidLoad() { @@ -84,7 +96,7 @@ extension MainVC { private func setData() { dataLinkedList.append(data: data) - currentNode = dataLinkedList.getFirstNode() + currentNode = dataLinkedList.getHead() } } @@ -95,6 +107,10 @@ extension MainVC { func nextButtonDidTap() { currentNode = currentNode?.next } + + func prevButtonDidTap() { + currentNode = currentNode?.prev + } } @@ -110,7 +126,7 @@ extension MainVC { } private func hierarchy() { - view.addSubviews(profileLabel, nextButton) + view.addSubviews(profileLabel, prevButton, nextButton) } private func layout() { @@ -119,7 +135,14 @@ extension MainVC { } nextButton.snp.makeConstraints { - $0.centerX.equalToSuperview() + $0.centerX.equalToSuperview().offset(50) + $0.top.equalTo(profileLabel.snp.bottom).offset(100) + $0.height.equalTo(40) + $0.width.equalTo(80) + } + + prevButton.snp.makeConstraints { + $0.centerX.equalToSuperview().offset(-50) $0.top.equalTo(profileLabel.snp.bottom).offset(100) $0.height.equalTo(40) $0.width.equalTo(80) diff --git a/SOPTving/SOPTving/Utility/DataStructure/LinkedList.swift b/SOPTving/SOPTving/Utility/DataStructure/LinkedList.swift index d386de6..9ef000e 100644 --- a/SOPTving/SOPTving/Utility/DataStructure/LinkedList.swift +++ b/SOPTving/SOPTving/Utility/DataStructure/LinkedList.swift @@ -8,6 +8,7 @@ import Foundation final class LinkedList { + private var head: Node? private var tail: Node? @@ -15,32 +16,31 @@ final class LinkedList { return head == nil } - func append(data: T?) { + func append(data: T) { let newNode = Node(data) if isEmpty { head = newNode tail = newNode - tail?.next = head } else { tail?.next = newNode + newNode.prev = tail tail = newNode - tail?.next = head } + + head?.prev = tail + tail?.next = head } // append 인자에 배열을 넣었을 경우, append(T)를 반복한다. - func append(data: [T]?) { - guard let data else { return } - for t in data { - append(data: t) + func append(data: [T]) { + for d in data { + append(data: d) } } - func getFirstNode() -> Node? { + func getHead() -> Node? { return head } - - } diff --git a/SOPTving/SOPTving/Utility/DataStructure/Node.swift b/SOPTving/SOPTving/Utility/DataStructure/Node.swift index 6244d4c..d98032f 100644 --- a/SOPTving/SOPTving/Utility/DataStructure/Node.swift +++ b/SOPTving/SOPTving/Utility/DataStructure/Node.swift @@ -8,11 +8,13 @@ import Foundation final class Node { - var data: T? + var data: T + var prev: Node? var next: Node? - init(_ data: T?, next: Node? = nil) { + init(_ data: T, prev: Node? = nil, next: Node? = nil) { self.data = data + self.prev = prev self.next = next } }