Chapter 1 Introduction to Data Structures and Algorithms










































- Slides: 42

Chapter 1 Introduction to Data Structures and Algorithms 235012 Data Structure and Algorithms 235012 : Data Structure and Algorithms







Algorithms ยกตวอยาง อลกอรธมใ ชงานเครอง คดเลขรวมตว เลข 235012 : Data Structure and Algorithms turn on calculator clear calculator repeat the following instructions key in baht amount key in decimal point key in satang amount press addition (+) key until all prices have been entered





Algorithms สญลกษณ ผงงาน 235012 : Data Structure and Algorithms

Algorithms START Get semester Y N if semester != 3 Max. Crd = 21 Max. Crd = 9 Get course Total. Crd = Total. Crd + Crd A 235012 : Data Structure and Algorithms B

Algorithms A Y Print “You can submit cause Total. Crd > Max. Crd” Total. Crd >= Max. Crd N Record Data to Master file Get request. Student if request is loop N 235012 : Data Structure and Algorithms B END Y





Algorithms คอมพวเตอรสามารถแสดงผลลพธได ในซโดโคดจะใชคำวา print (เครองพมพ ), write (บนทกลงในไฟล ), put, output หรอ display print (จอภาพ) “Program Complte” ตวอยางซ โดโคด ใชแสดงผลข อมล 235012 : Data Structure and Algorithms write customer record to master file put name, address and postcode output total. Tax display “End of data” prompt for student. Name




Algorithms คอมพวเตอรสามารถทำงานซำได § ในซโดโคดจะใชคำเฉพาะ คอ dowhile … enddo § หรอใชคำเฉพาะ คอ repeat…. until…. dowhile file_flage <> “eof” ตวอยางซ โดโคด ใชแสดงการ ทำงานซำ read student record print student. Name, address to report add 1 to student. Total enddo 235012 : Data Structure and Algorithms





Algorithms ตวอยาง 1 ตวอยาง 2 ประโยคคำสง if อยางงาย if money < 3000 then service. Chage = 5. 00 else service. Chage = 2. 00 end if ประโยคคำสง if ทไมมเงอนไขเทจ if money < 3000 then service. Chage = 5. 00 end if 235012 : Data Structure and Algorithms

Algorithms ตวอยาง ประโยคคำสง or/ not ในเงอนไข 3 4 if ทใชโอเปอรเรเตอร and/ if (money > 1000) and (money < 3000 ) then service. Chage = 5. 00 else add 1 to money end if if (money > 1000) or (money > 2000 ) then service. Chage = 5. 00 else add 1 to money end if 235012 : Data Structure and Algorithms

Algorithms ตวอยาง ประโยคคำสง or/ not ในเงอนไข 3 4 if ทใชโอเปอรเรเตอร and/ if (record. Code=“ 23” or update. Code=deleate) and account. Balance = zero then delete customer record end if if not (record. Code=“ 23” or update. Code=deleate) then delete customer record end if 235012 : Data Structure and Algorithms

Algorithms ตวอยาง 5 ประโยคคำสง if ซอนกน if record. Code = “A” then increment counter_A else if recoud. Code = “B” then increment counter_B else if recoud. Code = “C” then increment counter_C else increment error. Counter end if 235012 : Data Structure and Algorithms


Algorithms ตวอยาง dowhile ซโดโคดการทำงานซำ ซโดโคดข นด set student. Total to zero dowhile student. Total < 50 read student record print student. Name, adress to report add 1 to student. Total enddo 235012 : Data Structure and Algorithms

Algorithms นอกจากลปชนด dowhile แลว ยงมลปอกชนดหนงคอ repeat … untill รปแบบซโดโค ดการควบคมแ บบเลอกทำงาน ซำชนด repeat 235012 : Data Structure and Algorithms repeat statement block : until condition is true

Algorithms ตวอยาง ซโดโคดการทำงานซำ repeat … untill ซโดโคดขนด set student. Total to zero repeat read student record print student. Name, adress to report add 1 to student. Total untill student. Total < 50 235012 : Data Structure and Algorithms

DATA STRUCTURE 235012 : Data Structure and Algorithms




