Data Structure Stack Code Node Push include stdio
- Slides: 74
자료 구조 (Data Structure)
▣ 자료구조 구현 ◈ Stack Code (Node , Push 함수 구현) #include <stdio. h> typedef struct stack{ int stack. Area[5]; int top; }Stack , *PStack; void Push(Stack *st , int data){ if(st->top>=((int)sizeof(st->stack. Area)/4)-1) { printf("Stack is FULLn"); return; } st->top++; st->stack. Area[st->top] = data; }
▣ 자료구조 구현 ◈ Stack Code (Pop 함수 구현) int Pop(Stack *st){ int data; if(st->top<0) { printf("Stack is EMPTYn"); return 0; } data = st->stack. Area[st->top]; st->top--; return data; }
▣ 자료구조 구현 ◈ Stack Code (main 함수 구현) void main(void) { Stack st; st. top = -1; Push(&st , 10); Push(&st , 20); Push(&st , 30); } printf("%dn" , , Pop(&st));
▣ 자료구조 구현 ◈ 분석 Stack 영역 top -1 main() [4] [3] [2] [1] st [0] stack. Area Stack st; st. top = -1;
▣ 자료구조 구현 ◈ 분석 Stack 영역 top -1 0 main() [4] [3] [2] stack. Area [1] 100번지 Push() 10 st [0] 100 &st 10 st data Push(&st , 10);
▣ 자료구조 구현 ◈ 분석 Stack 영역 top 1 0 main() [4] [3] [2] 100번지 Push() st 20 [1] 10 [0] stack. Area 100 &st 20 st data Push(&st , 20);
▣ 자료구조 구현 ◈ 분석 Stack 영역 top 2 1 main() [4] [3] 100번지 Push() st 30 [2] 20 [1] 10 [0] stack. Area 100 &st 30 st data Push(&st , 30);
▣ 자료구조 구현 ◈ 분석 Stack 영역 top 1 2 main() [4] [3] 100번지 Pop() printf("%dn" , Pop(&st)); st 30 [2] 20 [1] 10 [0] stack. Area 30 100 &st 30 st data
▣ 자료구조 구현 ◈ 분석 Stack 영역 top 0 1 main() [4] [3] 100번지 Pop() printf("%dn" , Pop(&st)); st 30 [2] 20 [1] 10 [0] stack. Area 20 100 &st 20 st data
▣ 자료구조 구현 ◈ 분석 Stack 영역 top -1 0 main() [4] [3] 100번지 Pop() printf("%dn" , Pop(&st)); st 30 [2] 20 [1] 10 [0] stack. Area 10 100 &st 10 st data
▣ 자료구조 구현 ◈ 분석 Stack 영역 top -1 main() [4] [3] 100번지 Pop() printf("%dn" , Pop(&st)); st 30 [2] 20 [1] 10 [0] stack. Area 0 100 &st st data
▣ 자료구조 구현 ◈ 스택(Stack) -. 연결리스트를 이용한 Stack 구현 입력(Push) 출력(Pop) Push(Data 1) Push(Data 2) Push(Data 3) Data 3 data link Pop( ) Data 2 data Top link Data 1 data Pop( ) link Pop( )
▣ 자료구조 구현 ◈ Stack Code (Node , Get. Node 함수 구현) #include <stdio. h> #include <stdlib. h> #define EMPTY 0 struct node { int data; struct node * link; }; typedef struct node Stack; Stack * Get. Node(){ Stack * tmp; tmp=(Stack *)malloc(sizeof(Stack)); tmp->link=EMPTY; return tmp; }
▣ 자료구조 구현 ◈ Stack Code (Push 함수 구현) void Push(Stack **top, int data){ Stack *tmp; tmp=*top; *top=Get. Node(); } (*top)->data=data; (*top)->link=tmp;
▣ 자료구조 구현 ◈ Stack Code (Pop 함수 구현) int Pop (Stack **top) { Stack *tmp; int num; if(*top==EMPTY){ printf("Stack is empty!!!!"); return NULL; } tmp=*top; num=tmp->data; *top=(*top)->link; } free(tmp); return num;
▣ 자료구조 구현 ◈ Stack Code (Main 함수 구현) void main () { Stack * top=EMPTY; Push(&top, 10); Push(&top, 20); Push(&top, 30); } printf("%d", Pop(&top));
▣ 자료구조 구현 ◈ 분석 Stack * top=EMPTY; Stack 영역 main() 0 *top
▣ 자료구조 구현 ◈ 분석 Push(&top, 10); Stack 영역 main() 100번지 Push() Get. Node() Heap 영역 0 1000 *top &top 100 10 0 **top data *tmp 1000번지 10 0 data *link
▣ 자료구조 구현 ◈ 분석 Push(&top, 20); Stack 영역 main() 100번지 Push() Get. Node() Heap 영역 1000 2000 *top &top 100 20 1000 **top data *tmp 2000번지 2000 *tmp 1000번지 20 1000 0 data *link 10 0 data *link
▣ 자료구조 구현 ◈ 분석 Push(&top, 30); Stack 영역 main() 100번지 Push() Get. Node() Heap 영역 2000 3000번지 *top &top 100 30 2000 **top data *tmp 2000번지 3000 *tmp 1000번지 30 2000 0 data *link 20 1000 data *link 10 0 data *link
▣ 자료구조 구현 ◈ 분석 printf("%d", Pop(&top)); Stack 영역 main() 100번지 Pop() Heap 영역 3000 2000 3000번지 *top 30 &top 100 30 3000 **top num *tmp 2000번지 1000번지 30 2000 data *link 20 1000 data *link 10 0 data *link
▣ 자료구조 구현 ◈ 분석 printf("%d", Pop(&top)); Stack 영역 main() 100번지 Pop() Heap 영역 2000 1000 *top 20 &top 100 20 2000 **top num *tmp 2000번지 1000번지 20 1000 data *link 10 0 data *link
▣ 자료구조 구현 ◈ 분석 printf("%d", Pop(&top)); Stack 영역 main() 100번지 Pop() Heap 영역 1000 0 *top 10 &top 100 10 1000 **top num *tmp 1000번지 10 0 data *link
▣ 자료구조 이해 ◈ 큐(Queue) -. 연결리스트를 이용한 Queue 구현 Front Data 1 data 출력 (dequeue) Data 2 link data Rear Data 3 link data Enqueue(Data 1) Dequeue( ) Enqueue(Data 2) Dequeue( ) Enqueue(Data 3) Dequeue( ) link 입력 (enqueue)
▣ 함수 ◈ 문제 #include <stdio. h> void Func( ); void main(void) { Func( ); } void Func( ) { printf("Func 함수 호출n"); Func( ); } main 함수 영역 Func 함수 영역 º º º
▣ 함수 ◈ 문제 #include <stdio. h> void Func( ); void main(void) { Func( ); } void Func( ) { int num = 0; if(num == 5) return; printf("Func 함수 호출n"); num++; Func(); } main 함수 영역 Func 함수 영역 0 1 num º º º
▣ 함수 ◈ 문제 #include <stdio. h> void Func( ); void main(void) { Func( ); } void Func( ) { static int num = 0; if(num == 5) return; printf("Func 함수 호출n"); num++; Func(); } 3 0 1 2 5 4 num main 함수 영역 Func 함수 영역 Func 함수 영역
▣ 함수 ◈ 문제 #include <stdio. h> void Func( ); void main(void) { Func( 1 ); } void Func( int num ) { if(num == 5) return; printf("Func 함수 호출n"); } Func( num+1 ); main 함수 영역 Func 함수 영역 1 num Func 함수 영역 2 num Func 함수 영역 3 num Func 함수 영역 4 num Func 함수 영역 5 num
▣ 자료구조 구현 ◈ 예제 -. 1 ~ 5 까지의 합을 구하는 함수를 작성하시오 (재귀함수 사용) #include <stdio. h> int Sum(int n) { if(n==5) { } Sum() 1 n + 14 = Sum() 2 n + 12 = Sum() 3 n + 9 = Sum() 4 n + 5 = Sum() 5 n return n; } return n+Sum(n+1); void main() { printf("%dn" , Sum(1)); } 15 main()
▣ 자료구조 구현 ◈ 연결 리스트(Linked List) -. 재귀함수를 이용한 연결리스트 구현(삽입) Head Data 1 data Insert. Node(Data 1) Insert. Node(Data 2) Insert. Node(Data 3) Data 3 Data 2 link data link
▣ 자료구조 구현 ◈ Linked List Code (Node , Get. Node 함수 구현) #include <stdio. h> #include <malloc. h> typedef struct node{ int data; struct node *link; }Linklist; Linklist * Get. Node(){ Linklist * ptr; ptr = (Linklist * ) malloc ( sizeof ( Linklist ) ); ptr->link=NULL; return ptr; }
▣ 자료구조 구현 ◈ Linked List Code (Insert. Node , main 함수 구현) void Insert. Node (Linklist **head, int data) { if ( *head == NULL ) { *head = Get. Node( ); (*head)->data = data; return ; } Insert. Node( &(*head)->link , data ); } void main ( ) { Linklist * head =NULL; } Insert. Node( &head, 10 ); Insert. Node( &head, 20 ); Insert. Node( &head, 30 );
▣ 자료구조 구현 ◈ 연결 리스트(Linked List) -. 재귀함수를 이용한 연결리스트 구현(추가) Head Data 1 data Data 3 Data 2 link data Data 4 data Add. Node(Data 1 , Data 4) link data link
▣ 자료구조 구현 ◈ 연결 리스트(Linked List) -. 재귀함수를 이용한 연결리스트 구현(삭제) Head Data 1 data Data 3 Data 2 link Delete. Node(Data 2) data link
▣ 자료구조 이해 ◈ 이진 탐색 트리(BINARY SEARCH TREE) 구현 -. 순서가 있는 이진 트리 Insert. Node(10) ROOT Left Insert. Node(20) data Right Insert. Node(5) 10 Insert. Node(15) 5 20 15
▣ 자료구조 구현 ◈ Tree Code (Node , Get. Node 함수 구현) #include <stdio. h> #include <malloc. h> typedef struct node { struct node *left; int data; struct node *right; }BST , *PBST; PBST Get. Node(){ PBST node = (PBST) malloc (sizeof (BST)); node->left = node->right = NULL; return node; }
▣ 자료구조 구현 ◈ Tree Code (Insert. Node 함수 구현) void Insert. Node(PBST *root , int data){ if ((*root) == NULL){ (*root) = Get. Node(); (*root)->data = data; } else if ((*root)->data > data ) Insert. Node(&(*root)->left, data); else Insert. Node(&(*root)->right, data); }
▣ 자료구조 구현 ◈ Tree Code (main 함수 구현) void main (){ PBST root = NULL; Insert. Node(&root, } 10); 20); 5); 15);
▣ 자료구조 이해 ◈ 이진 탐색 트리(BINARY SEARCH TREE) 삭제 Delete. Node(5) ROOT Left data Right 10 5 20 15
▣ 자료구조 이해 ◈ 이진 탐색 트리(BINARY SEARCH TREE) 삭제 Delete. Node(20) ROOT Left data Right 10 5 20 15
▣ 자료구조 이해 ◈ 이진 탐색 트리(BINARY SEARCH TREE) 삭제 Delete. Node(20) ROOT Left data Right 10 5 20 15 15
▣ 자료구조 이해 ◈ 이진 탐색 트리(BINARY SEARCH TREE) 삭제 Delete. Node(10) ROOT Left data Right 10 15 5 20 15
- #include stdio.h #include conio.h #include stdlib.h
- Include stdlib
- Include stdlib h
- #include stdlib.h
- Struct node int data struct node* next
- Reference node and non reference node
- Reference node and non reference node
- Constructive interference of standing waves
- Typedef struct node
- Russell-saunders coupling
- Push hard push fast fully recoil
- Push hard push fast fully recoil
- Push hard push fast fully recoil
- Resuscitation triangle roles
- Capnoea
- Mild foreign-body airway obstruction
- #include stdio.h void main()
- ##include stdio.h
- Stdlib.h
- #include stdio.h int main() int i = 5
- #include stdio.h int main()
- Stdio
- #include stdio.h void main()
- Struct sample int a
- #include stdio.h
- #include stdio.h
- Include stdio.h
- #include stdio h
- #include stdio h
- Lpthread
- 저장 유형 지정자
- 쉽게 풀어쓴 c언어 express 2장
- H
- Include stdio.h
- #define _crt_secure_no_warnings
- #include stdio.h void main()
- Push(stack,l)
- Push and pop in stack
- Stack smash attack
- Stack grows downwards
- Stack=[] digunakan untuk membuat stack dengan
- Stack data structure exercises
- Queue is a static data structure
- Data structure stack
- Postfix expression
- Busceral
- Iostream
- #include iostream using namespace std
- #include iostream #include cmath
- #include iostream
- #include iostream using namespace std
- Include namespace std
- Debounce verilog
- Lymph node structure
- Lymphoid
- Lymph node structure
- Struct node int data
- Push adalah operasi untuk memasukkan data ke
- Hci design patterns