1. วิธีแก้ปัญหา
1.1. เปลี่ยนเป็น Postfix
1.1.1. โดย การใช้ Array , stack , dictionary
1.2. กำหนดเงื่อนไข
1.2.1. ตัวเลขที่ใส่เข้ามา เก็บไว้ใน array
1.2.2. เครื่องหมาย นำมาเก็บใว้ใน Stack
1.2.2.1. ถ้า stack ว่าง ก็ใช้เครื่องหมายนั้นเลย
1.2.2.2. ถ้า stack ไม่ว่าง ให้เปรียบเทียบตัวบน (a) กับ ตัวใหม่ (b) if (b>a) ให้ push b ลง stack else pop a ไปใส่ใน array แล้ว push b ลง stack
1.2.2.3. ทำ 1 และ 2
2. ความรู้ที่ต้องใช้
2.1. array
2.1.1. int[] arr= new int[];
2.1.1.1. เก็บตัวเลข
2.2. stack
2.2.1. Stack myStack = new Stack(); myStack.Push("Hello"); myStack.Push("World"); myStack.Push("!");
2.2.1.1. เก็บเครื่องหมาย
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.3.1.1. กำหนดค่าความสำคัญให้กับเครื่องหมาย
2.4. try cath
2.4.1. ใช้กับ int.parse ในกรณีที่ไม่เป็นตัวเลข
2.4.1.1. ใช้ cath แก้ปัญหา ในกรณีที่ ตัวเลข int.parse แล้ว error
2.5. int.parse
2.6. substring
2.6.1. Example code string sentence = "This sentence has five words."; int startPosition = sentence.IndexOf(" ") + 1; string word2 = sentence.Substring(startPosition, sentence.IndexOf(" ", startPosition) - startPosition);
2.6.2. ใช้ ในการตรวจสอบว่าเป็นตัวเลขหรือไม่
2.6.3. ใช้ตรวจสอบตัวเลข ในกรณีที่เป็นเลข สองหลัก สามหลัก
2.6.3.1. ถ้าตรวจสอบตัวแรกเป็นตัวเลข และตัวต่อไปก็เป็นตัวเลข โดยใช้ int.pase ถ้าเกิด error ก็ให้ทำที่ cath
2.7. foreach
2.7.1. foreach (var item in collection) {}
2.7.2. ใช้ในการวนลูป ใน stack, list และ string
2.7.2.1. เพื่อแยก string และนำข้อมูลใน stack และ list มาใช้ในการคำนวณ
3. วิธีการคำนวณ
3.1. แปลง 5-10+5*25/5 เป็น Postfix
3.1.1. array
3.1.1.1. 5
3.1.1.1.1. 10
3.1.2. Stack
3.1.2.1. -
3.1.2.1.1. +
3.2. คำนวณ
3.2.1. 5 10-5 25*5/+
3.2.1.1. stack
3.2.1.1.1. 5