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

1. คิด Postfix

1.1. นิยาม

1.1.1. A = ค่าใน stack ตัวท้ายสุด

1.1.2. B = ค่าใน stack ตัวถัดจาก A

1.2. rule

1.2.1. 1.

1.2.1.1. ถ้าเจอตัวเลขเก็บเข้า stack

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

1.2.2. 2.

1.2.2.1. ถ้าเจอเครื่องหมายให้ pop A และ pop B แล้วนำมาคำนวณเครื่องหมาย เช่น B+ A

1.2.2.1.1. stack Stack ชื่อ = new Stack(); int sum1 = ชื่อ.myStack.Pop(A) int sum = ชื่อ.myStack.Pop(B) เช่น sum += sum1

1.2.3. 3.

1.2.3.1. นำค่าที่ได้จากข้อ 2. ลงใน stack

1.2.4. 4.

1.2.4.1. ทำข้อ 1. 2. 3. จนหมดแล้วนำค่าใน stack มาแสดง

2. ตัวอย่างการคิด Postfix

2.1. 5 1 2 + * 10+

2.1.1. stack

2.1.1.1. 5

2.1.1.1.1. 1

3. ความรู้ที่ต้องใช้

3.1. stack

3.1.1. stack Stack ชื่อ = new Stack(); ชื่อ.Push(สิ่งที่ต้องการใส่ลงใน Stack); ชื่อ.Pop(สิ่งที่ต้องการนำออกใน Stack);

3.2. substring

3.2.1. ตัดมาคิดทีละตัว

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

3.3. array

3.3.1. int[] ชื่อ

3.4. dictionary + - = 1 , * / = 2

3.4.1. Dictionary<string, string> ชื่อ = new Dictionary<string, string>(); ชื่อ.Add(+,1); ชื่อ.Add(-,1); ชื่อ.Add(*,2); ชื่อ.Add(/,2);

3.5. if-else

3.5.1. if (true){} else {}

3.6. try-catch

3.6.1. try {} catch (InvalidCastException e) { }

4. เปลื่ยนเป็น Postfix

4.1. rule

4.1.1. dictionary + - = 1 , * / = 2

4.1.1.1. Dictionary<string, string> ชื่อ = new Dictionary<string, string>(); ชื่อ.Add(+,1); ชื่อ.Add(-,1); ชื่อ.Add(*,2); ชื่อ.Add(/,2);

4.1.2. วิธีการหาตัวเลข

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

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

4.1.2.3. 3. ทำ ข้อ1และข้อ2 ไปเรื่อยๆจนกว่าจะเจอเครื่องหมาย

4.1.2.4. 4. เปลี่ยนเป็นตัวเลข

4.1.2.4.1. int.parse(num)

4.1.3. 1. เจอตัวเลขเอาไปเก็บไว้ใน Array

4.1.3.1. arr[] = num

4.1.4. 2. เจอเครื่องหมายนำไปใส่ใน Stack

4.1.4.1. 1. ถ้า Stack ว่างก็ใช่เครื่องหมายนั้นได้เลย

4.1.4.2. 2. ถ้า Stack ไม่ว่าง ให้เปรียบเทียบตัวบน (a) กับตัวใหม่ (b) if (b>a) ให้push b ลง stack else pop a ไปใส่ใน array แล้ว push b ลง stack

4.1.4.3. ทำ 1 และ 2

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

5.1. แปลง 5+1*2+10

5.1.1. array

5.1.1.1. 5

5.1.1.1.1. 1

5.1.2. stack

5.1.2.1. +

5.1.2.1.1. *