Get Started. It's Free
or sign up with your email address
Calculator by Mind Map: Calculator

1. เปลี่ยนเป็นpostfix

1.1. array

1.1.1. int[] ชื่อ

1.2. stack

1.2.1. stack Stack ชื่อ =new stack(); ชื่อpush(สิ่งที่ต้องการใส่ลงใน stack); ชื่อmyStackPop

1.3. rule

1.3.1. dictionary

1.3.1.1. +,- =1

1.3.1.2. *,/=2

1.3.2. 1.เจอตัวเลขเอาไปใส่ในarray

1.3.3. 2.เจอเครื่องหมายเอาไปใส่ในstack

1.3.3.1. ถ้าstackว่างใส่ค่าได้เลย

1.3.3.2. ถ้าstackไม่ว่างให้ดูที่dicว่าอะไรมีค่าน้อยกว่ามากกว่าหรือเท่ากัน popค่ามากกว่าไปลงในarray แล้ว push ค่าน้อยกว่าลงในstack

1.3.3.3. ทำ 1 และ 2 ไปเรื่อยๆเมื่อทำเสร็จนำstack ไปใส่ใน array

1.3.4. วิธีการตัวเลขจาก array

1.3.4.1. 1.เจอตัวแรกเก็บไว้ในตัวแปร num

1.3.4.2. 2.ถ้าตัวถัดไปเป็นตัวเลขให้นำมารวมกับตัวแรก

1.3.4.3. 3.ถ้าเจอเครื่องหมายให้ push ลง stack

2. ข้อมูลที่ต้องใช้

2.1. Array

2.1.1. int[]ชื่อ

2.2. Stack

2.2.1. stack Stack ชื่อ =new stack(); ชื่อpush(สิ่งที่ต้องการใส่ลงใน stack); ชื่อmyStackPop

2.3. Dictionary

2.3.1. Dictionary<string, int> dictionary = new Dictionary<string, int>(); dictionary.Add("*", 2); dictionary.Add("/", 2); dictionary.Add("+", 1); dictionary.Add("-", 1);

2.4. Try cath

2.4.1. ใช่กับ int.parse ในกรณีที่ไม่เป็นตัวเลข

2.5. int.parse

2.5.1. ใช้ตรวจสอบว่าเป็นตัวเลขหรือไม่

2.6. substring

2.6.1. คิดทีละตัว

2.6.1.1. string sentence = "This sentence has five words."; int startPosition = sentence.IndexOf(" ") + 1; string word2 = sentence.Substring(startPosition, sentence.IndexOf(" ", startPosition) - startPosition); Console.WriteLine("Second word: " + word2);

3. ตัวอย่างการทำให้เป็น postfix

3.1. 9+5*2/2

3.1.1. arry

3.1.1.1. 9

3.1.1.1.1. 5

3.1.2. stack

3.1.2.1. +

3.1.2.1.1. *

3.1.3. คำนวณ

3.1.3.1. 9

3.1.3.1.1. 5