1. กฏของการคำนวณ Postfix
1.1. 1. ถ้าเจอตัวเลขให้เก็บไว้ใน array
1.2. 2. ถ้าเจอเครื่องหมาย ให้เอาตัวเลขที่อยู่ในarray 2 ตัวหลัง มาคำนวณ แล้วเก็บค่าไว้ใน array
1.3. 3. ให้ตัวแรกเป็น a ตัวที่สองเป็น b เช่น a,b = a + b
2. วิธีคำนวณ Postfix
2.1. Array
2.1.1. เก็บค่าตัวเลข
2.2. Stack
2.2.1. เก็บเครื่องหมาย
2.3. 2 3 3 * 3 / + 1 -
2.3.1. Array
2.3.1.1. 2
2.3.1.1.1. 3
2.3.2. Stack
2.3.2.1. *
2.3.2.1.1. /
3. สิ่งที่นำไปใช้ในการคำนวณ
3.1. Try Catch
3.1.1. ใช้กับ int.parse ในกรณีที่ไม่มีตัวเลข
3.1.2. Catch .ใช้แก้ไขตัวเลขเมื่อ int.parse เกิดการ error
3.2. Int.Parse
3.2.1. ใช้แปลงค่า เพื่อตรวจสอบตัวเลข
3.3. Dictionary
3.3.1. Dictionary<string, int> dictionary = new Dictionary<string, int>();
3.3.2. dictionary.Add("*",2);
3.3.3. dictionary.Add("/",2);
3.3.4. dictionary.Add("+",1);
3.3.5. dictionary.Add("-",1);
3.4. String
3.4.1. string sentence = "This sentence has five words."; // Extract the second word. int startPosition = sentence.IndexOf(" ") + 1; string word2 = sentence.Substring(startPosition, sentence.IndexOf(" ", startPosition) - startPosition); Console.WriteLine("Second word: " + word2);
4. วิธีแปลงเป็นPostfix
4.1. Array
4.1.1. int[]arr = new int[] ;
4.1.1.1. เก็บค่าตัวเลข
4.1.1.1.1. 1. ถ้าตัวเลขมีมากกว่าหนึ่งหลัก ให้เก็บตัวเลขแรกไว้
4.1.1.1.2. 2.ตรวจสอบว่าค่าถัดไปเป็นตัวเลขหรือไม่ ถ้าใช่ ให้นำมาต่อตัวเลขแรก
4.2. Stack
4.2.1. Stack myStack = new Stack(); myStack.Push("Hello"); myStack.Push("World"); myStack.Push("!");
4.2.1.1. เก็บเครื่องหมาย
4.2.1.1.1. เครื่องหมาย ^ = 2
4.2.1.1.2. เครื่องหมาย * , / = 1
4.2.1.1.3. เครื่องหมาย + , - = 0
4.3. กฎในการแปลง Postfix
4.3.1. 1. ถ้าเป็นตัวเลขเก็บไว้ใน array
4.3.2. 2. ถ้าเครื่องหมายที่อยู่ใน stack มีค่ามากกว่าหรือเท่ากับ เครื่องหมายที่อยู่นอก stack ให้ pop เครื่องหมายที่อยู่ใน stack ออกไปไว้ใน array
5. 2+3*3/3-1
5.1. Array
5.1.1. 2
5.1.1.1. 3
5.1.1.1.1. 3
5.2. Stack
5.2.1. +
5.2.1.1. *
5.2.1.1.1. /