언젠가는 되어있겠지
데이터 공부 노트
언젠가는 되어있겠지
전체 방문자
오늘
어제
  • 분류 전체보기 (410)
    • Programming (14)
      • Python (6)
      • Algorithm (8)
    • OS (9)
      • Linux (9)
    • DBMS (2)
      • MySQL (2)
    • IoT Apps (6)
      • AppInventor (5)
      • Arduino (1)
    • LeetCode (151)
      • Easy (136)
      • Medium (13)
      • Hard (2)
    • Course (207)
      • [IBM] Data Science (9)
      • [IBM] Data Engineering (5)
      • [Inflearn] Pandas (12)
      • [Inflearn] Public Data Anal.. (8)
      • [Kaggle] Data Science (49)
      • [Youtube] Informations (2)
      • [Coursera] Machine Learning (40)
      • [Progrmiz] Data Structure A.. (15)
      • [DataQuest] Data Engineerin.. (67)
    • Data Engineering (20)
      • [Data Quest] Handling Datas.. (16)
      • [Data Quest] Data Pipeline (4)
    • Certificate (0)
      • 빅데이터 분석기사 (0)
    • SQLD (0)
    • 하고 싶은 이야기 (0)
    • 소설 (0)

블로그 메뉴

  • 홈
  • 태그

공지사항

인기 글

태그

  • Kaggle Course
  • Data Science

최근 댓글

최근 글

티스토리

hELLO · Designed By 정상우.
언젠가는 되어있겠지

데이터 공부 노트

[DS1] Stack
Course/[Progrmiz] Data Structure Algorithm

[DS1] Stack

2022. 8. 10. 21:16

1. Whta is Stack

A stack is a linear data structure that follows the principle of Last in First Out(LIFO). This means the last element inserted inside the stack is removed first.

 

2. LIFO Principle of Stack

In programming terms, putting an item on top of the stack is called push and removing an item is called pop.

 

3. Basic Operations of Stack

  • Push : Add an element to the top of a stack
  • Pop : Remoe an element from the top of a stack
  • IsEmpty : Check if the stack is empty
  • IsFull : Check if the stack is full
  • Peek : Get the value of the top element without removing it

 

4. Working of Stack Data Structure

  1. A pointer called TOP is used to keep track of the top element in the stack.
  2. When initializing the stack, we set its value to -1 so that we can check if the stack is empty by comparing TOP == -1.
  3. On pushing an element, we increase the value of TOP and place the new element in the position pointed to by TOP.
  4. On popping an element, we return the element pointed to by TOP and reduce its value
  5. Before pushing, we check if the stack is already full.
  6. Before popping, we check if the stack is already empty.

 

5. Stack Implementation

class Stack: 
    def __init__(self): 
        self.stack = [] 
        
    def is_empty(self, stack): 
        return len(self.stack) == 0
    
    def push(self, item): 
        self.stack.append(item) 
        print(f"Pushed item: {item}")
        
    def pop(self): 
        if self.is_empty(self.stack): 
            print(f"Stack is empty")
        return self.stack.pop()

 

6. Source

https://www.programiz.com/dsa/stack

 

'Course > [Progrmiz] Data Structure Algorithm' 카테고리의 다른 글

[DS1] Types of Queue  (0) 2022.08.16
[DS1] Queue  (0) 2022.08.10
[Introduction] Divide and Conquer Algorithm  (0) 2022.08.09
[Introduction] Asymptotic Notations  (0) 2022.08.08
[Introduction] Why Learn DSA?  (0) 2022.08.08
    'Course/[Progrmiz] Data Structure Algorithm' 카테고리의 다른 글
    • [DS1] Types of Queue
    • [DS1] Queue
    • [Introduction] Divide and Conquer Algorithm
    • [Introduction] Asymptotic Notations
    언젠가는 되어있겠지
    언젠가는 되어있겠지

    티스토리툴바