Data Journey

International Studies Grad. racing for AI Engineer

Download as .zip Download as .tar.gz View on GitHub
19 December 2020

Linear Data Structure: Stack, Queue

by mervyn

Stack

A collection of elements that are inserted and removed according to the last-in first-out (LIFO) orders

Stack: Terminologies

Parenthesis Matching

Check if each opening parenthesis has a corresponding closing one. Example:

Parenthesis Matching with Stack

Queue

A collection of elements that are inserted and removed according to the first-in first-out (FIFO) orders.

Queue: Terminologies

Linear Queue

Problem: We cannot add anymore although we have empty spaces.

Circular Queue

A queue with cyclic rear and front indices to fully utilize the space.

STL (Standard Template Library)

A software library for the C++ programming language.

Palindrome Check

A palindrome is a sequence of characters which reads the same backward as forward. (e.g.: radar, rotator, level)

#include <cstring>
#include <stack>
#include <queue>

bool Check_Palindrome(const char *_str)
{
  std::stack<char> s;
  std::queue<char> q;

  int len = strlen(_str);
  for(int i=0;i<len;i++);
  {
    s.push(_str[i]);
    q.push(_str[i]);
  }

while(!s.empty())
  {
    if(s.top()!=q.front())
      return false;
    s.pop();
    q.pop();
  }
  return true;
}

source “K-MOOC 허재필 교수님의 <인공지능을 위한 알고리즘과 자료구조: 이론, 코딩, 그리고 컴퓨팅 사고> 강좌의 2-2 강좌의 스택과 큐 중(http://www.kmooc.kr/courses/course-v1:SKKUk+SKKU_46+2020_T1)”

back next

tags:

Comments

Post comment
Loading...

Share this: