-
연결 리스트 스택 (Linked List Stack)언어/C, C++ 2021. 1. 13. 16:07
#pragma once struct Node { int data; Node* next; }; class LinkedListStack { private: Node* m_top; public: LinkedListStack(); ~LinkedListStack(); void Push(int _item); int Pop(); bool IsEmpty(); };
LinkedListStack.h
#include "LinkedListStack.h" LinkedListStack::LinkedListStack() : m_top(nullptr) { } LinkedListStack::~LinkedListStack() { } void LinkedListStack::Push(int _item) { Node* temp = new Node; temp->data = _item; temp->next = m_top; m_top = temp; } int LinkedListStack::Pop() { int tempData = m_top->data; Node* tempNode = m_top; m_top = m_top->next; delete tempNode; return tempData; } bool LinkedListStack::IsEmpty() { return m_top == nullptr; }
LinkedListStack.cpp
'언어 > C, C++' 카테고리의 다른 글
연결 리스트 큐 (LinkedList Queue) (0) 2021.01.19 배열 큐 (Array Queue) (0) 2021.01.19 배열 스택 (Array Stack) (0) 2021.01.12 이중 연결 리스트 (DoubleLinkedList) (0) 2021.01.05 연결 리스트 (Linked List) (0) 2020.12.31