1 / 19

Stack 204311 การจัดการแฟ้มข้อมูลและโครงสร้างข้อมูล File Management and Data Structure

Stack 204311 การจัดการแฟ้มข้อมูลและโครงสร้างข้อมูล File Management and Data Structure. บรรยายครั้งที่ 2 : Stack. วัตถุประสงค์ : นักศึกษาสามารถ อธิบายโครงสร้างข้อมูลแบบ Stack ได้ถูกต้อง

lewis
Download Presentation

Stack 204311 การจัดการแฟ้มข้อมูลและโครงสร้างข้อมูล File Management and Data Structure

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Stack204311การจัดการแฟ้มข้อมูลและโครงสร้างข้อมูลFile Management and Data Structure

  2. บรรยายครั้งที่ 2:Stack • วัตถุประสงค์ : นักศึกษาสามารถ • อธิบายโครงสร้างข้อมูลแบบ Stack ได้ถูกต้อง • เขียนโปรแกรมด้วยภาษา Visual Basicในการดำเดินการต่าง ๆ ตามโครงสร้างข้อมูลแบบ Stack ได้แก่การ Push และ Pop

  3. หัวข้อการบรรยาย • แนะนำ Stack • โอเปอร์เรชั่นพื้นฐานที่ทำกับแสตก • แสตกรูปแบบอื่นๆ • การประยุกต์ใช้แสตก

  4. แนะนำ Stack

  5. แนะนำ Stack C B A

  6. แนะนำ Stack C B A

  7. แนะนำ Stack E D F B A

  8. แนะนำ Stack E D F B A

  9. แนะนำ Stack D F B A

  10. ขบวนการพื้นฐานที่ทำกับแสตกขบวนการพื้นฐานที่ทำกับแสตก • Push • Pop • Empty • Full

  11. ขบวนการพื้นฐานที่ทำกับแสตกขบวนการพื้นฐานที่ทำกับแสตก • ตัวอย่าง

  12. ขบวนการพื้นฐานที่ทำกับแสตกขบวนการพื้นฐานที่ทำกับแสตก // Stack.cpp #include <stdio.h> #include <conio.h> int top = 0; void PrintStack(char *); int Push(char *, char); char Pop(char *); int IsEmpty(char *); // 0Not Empty, 1Empty int IsFull(char *); // 0Not Full, 1Full

  13. ขบวนการพื้นฐานที่ทำกับแสตกขบวนการพื้นฐานที่ทำกับแสตก main() { char select=0; char stack[10] = {'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0'}; char element; clrscr(); do { printf("\n\nMenu\n"); printf("======\n"); printf("1. Push\n"); printf("2. Pop\n"); printf("3. Exit\n"); printf("Please select operation: "); select = getche(); switch(select) { case '1': printf("\nEnter a character to push: "); element = getche(); Push(stack, element); break; case '2': printf("\nPop stack and get: %c", Pop(stack)); break; default : break; } PrintStack(stack); } while(select != '3'); return(0); }

  14. ขบวนการพื้นฐานที่ทำกับแสตกขบวนการพื้นฐานที่ทำกับแสตก printf("1. Push\n"); printf("2. Pop\n"); printf("3. Exit\n"); printf("Please select operation: "); select = getche(); switch(select) { case '1': printf("\nEnter a character to push: "); element = getche(); Push(stack, element); break; case '2': printf("\nPop stack and get: %c", Pop(stack)); break; default : break;

  15. ขบวนการพื้นฐานที่ทำกับแสตกขบวนการพื้นฐานที่ทำกับแสตก int Push(char * stack, char element) { stack[top] = element; top += 1; // incrase top by 1 return top; }

  16. ขบวนการพื้นฐานที่ทำกับแสตกขบวนการพื้นฐานที่ทำกับแสตก char Pop(char * stack) { char topelement; topelement=stack[top-1]; stack[top-1]='\0'; top -= 1; return(topelement); }

  17. ขบวนการพื้นฐานที่ทำกับแสตกขบวนการพื้นฐานที่ทำกับแสตก void PrintStack(char * stack) { int i = 0; printf("\n"); for(i=9;i>=0;i--) { printf("\n | %c |", stack[i]); } printf("\n _____"); printf("\n Top : %d", top); }

  18. แสตกรูปแบบอื่นๆ • ลิงค์แสตก

  19. กระประยุกต์ใช้แสตก • การคำนวณ และการแปลงนิพจน์ทางคณิตศาสตร์ • แนวคิดในการคอมไพล์ • Factorials • Fibonacci

More Related