Stack kjsspacedaum net Stack Array StackLinked List class
- Slides: 21
스택(Stack) 김진수 kjsspace@daum. net
Stack (Array)
Stack(Linked List)
스택(배열이용) class Stack. Array { public: Stack. Array(void); Stack. Array(const Stack. Array & S); //복사생성자 ~Stack. Array(void); void Push(int Item); bool Is. Empty(void); bool Is. Full(void); private: int Top; int Stack[100]; };
Stack. Array: : Stack. Array( ) { } Top = 0; // 생성자 함수 //탑 인덱스 0으로 초기화 Stack. Array: : Stack. Array(const stack. Class& S) { } Top = S. Top; // Top 인덱스를 복사 for (int Index = 0; Index <= S. Top; ++ Index) // 인덱스 0부터 S. Top까지 Stack[Index] = S. Stack[Index]; // 배열 요소 복사 Stack. Array: : ~Stack. Array( ) { } bool Stack. Array: : Is. Empty( ) { } // 복사생성자 return (Top = = 0); // 소멸자 함수 // 실행할 일 없음 // 빈 스택인지 확인하는 함수 // 탑 인덱스 0 이면 TRUE
bool Stack. Array: : Is. Full( ) { } return (Top = = 100); // 탑 인덱스 100이면 TRUE void Stack. Array: : Push(int Item) { } Top=Top+1; Stack[Top]=Item; int Stack. Array: : Pop( ) { } return Stack[Top--]; // 꽉찬 스택인지 확인하는 함수 // Item 값을 스택에 삽입
Stack Test #1 #include<iostream> #include"Stack. Array. h" using namespace std; void main() { } Stack. Array st; for(int i=1; i<=10; i++) st. Push(i); for(int i=1; i<=10; i++) cout << st. Pop() << endl;
Stack Test #2 #include<iostream> #include"Stack. Array. h" using namespace std; void main() { } Stack. Array st 1; for(int i=1; i<=10; i++) st 1. Push(i); Stack. Array st 2(st 1); for(int i=1; i<=10; i++) cout << st 2. Pop() << endl;
스택(Linked List) class Node { public: }; Node(void); ~Node(void); int data; Node *next;
#include "Node. h“ Node: : Node(void){ data = 0; next = NULL; } Node: : ~Node(void){ }
#include"Node. h" class Stack. Class { public: Stack. Class(void); ~Stack. Class(void); private: Node *head; public: void Push(int item); int Pop(void); bool is. Empty(void); bool is. Full(void); };
#include "Stack. Class. h" #include <iostream> Stack. Class: : Stack. Class(void){ head = new Node; } Stack. Class: : ~Stack. Class(void){ delete head; } void Stack. Class: : Push(int item){ Node *new. Node = new Node; if(new. Node!=NULL){ new. Node->next = head; head->data = item; head = new. Node; } }
int Stack. Class: : Pop(void){ if(!is. Empty()){ Node *current = head->next; head = head->next; return current->data; } return 9999; } bool Stack. Class: : is. Empty(void){ return (head->next==NULL); } bool Stack. Class: : is. Full(void){ return false; }
Stack Test#3 #include<iostream> #include"Stack. Class. h" using namespace std; int main() { Stack. Class *a = new Stack. Class; for(int i=1; i<=10; i++) a->Push(i); } for(int i=1; i<=10; i++) cout << a->Pop() << endl; delete a; return 0;
Stack 사용예
후위표기법 계산 blog. daum. net/kjsspace
- Stack smashing
- Characteristics of assembly language
- Stack=[] digunakan untuk membuat stack dengan
- Deque list
- Stack queue python
- Lga vs pga
- Deklarasi array x adalah int a 2 4 5
- Jagged array
- Associative array vs indexed array
- Compare broadside and endfire array
- Apa itu larik
- Sparse array adalah array yang
- Multidimensional array python
- Photovoltaic array maximum power point tracking array
- Java array to list
- Difference between an array and a linked list
- Array based implementation of list adt
- Array list and vector in java
- Dot java
- Array disadvantages
- Class diagram array
- Array class java