Sistem dizaynı ilə bağlı müsahibə sualları o qədər açıq ola bilər ki, düzgün hazırlaşmağı bilmək çox çətindir. İndi satın aldıqdan sonra Amazon, Microsoft və Adobe-nin dizayn dövrlərini sındıra bilirəm Bu kitabı. Gündəlik bir yenidən nəzərdən keçirin dizayn sualı və söz verirəm ki, dizayn dövrünü sındıra bilərsiniz.
Mündəricat
İnfiks ifadəsi nədir?
'Operand' 'operator' 'operand' 'şəklində ifadəyə infix ifadə deyilir.
Misal: a + b
Postfiks ifadəsi nədir?
'Operand' 'operand' 'operator' şəklində ifadəyə postfiks ifadəsi deyilir.
Misal: ab +
Postfiks konversiyasına əlavə etmək üçün nə lazımdır?
Infix ifadəsini insanlar üçün başa düşmək asandır, ancaq kompüter arasında fərq qoyula bilməz mötərizələr və operatorlar asanlıqla bir infix ifadəsini postfix ifadəsinə çeviririk.
İnfiksi Postfiksə necə çevirmək olar?
- İnfiks ifadəsini soldan sağa tarayın. Operandı a daxil edin postfiks ifadəsi.
- Başqa bir şey, xarakterin üstünlüyü yığının və ya yığının içərisindəki xarakterdən daha yüksəkdirsə '' 'üstdə və ya yığında boşdur, sadəcə xarakteri yığına itələyin.
- Əks təqdirdə, yığındakı bütün simvolları açın və skan edilmiş simvoldan daha az üstünlüyə malik bir simvol və ya '(' tapılıncaya qədər skan edilmiş xarakteri itələyənə qədər postfiks ifadəsinə qoyun.
- Taranan simvol '(') olduqda yığına itələyin.
- Taranan simvol ')' olduqda, bütün simvolları yığından çıxarın və onları '(' tapılana qədər yığışdırın '(') postfiks ifadəsinə əlavə edin.
- Bütün simvollar üçün 1-5 addımlarını təkrarlayın.
- Yığından yığına qədər bütün simvolları atın boş olur və onları postfiks ifadəsinə əlavə edin.
Infix-dən Postfiks üçün C ++ kodu
/* C++ implementation to convert infix expression to postfix*/ // Note that here we use std::stack for Stack operations #include<bits/stdc++.h> using namespace std; //Function to return precedence of operators int prec(char c) { if(c == '^') return 3; else if(c == '*' || c == '/') return 2; else if(c == '+' || c == '-') return 1; else return -1; } // The main function to convert infix expression //to postfix expression void infixToPostfix(string s) { std::stack<char> st; st.push('N'); int l = s.length(); string ns; for(int i = 0; i < l; i++) { // If the scanned character is an operand, add it to output string. if((s[i] >= 'a' && s[i] <= 'z')||(s[i] >= 'A' && s[i] <= 'Z')) ns+=s[i]; // If the scanned character is an ‘(‘, push it to the stack. else if(s[i] == '(') st.push('('); // If the scanned character is an ‘)’, pop and to output string from the stack // until an ‘(‘ is encountered. else if(s[i] == ')') { while(st.top() != 'N' && st.top() != '(') { char c = st.top(); st.pop(); ns += c; } if(st.top() == '(') { char c = st.top(); st.pop(); } } //If an operator is scanned else{ while(st.top() != 'N' && prec(s[i]) <= prec(st.top())) { char c = st.top(); st.pop(); ns += c; } st.push(s[i]); } } //Pop all the remaining elements from the stack while(st.top() != 'N') { char c = st.top(); st.pop(); ns += c; } cout << ns << endl; } //Driver program to test above functions int main() { string exp = "a+b*(c^d-e)^(f+g*h)-i"; infixToPostfix(exp); return 0; }
Infix - Postfix üçün Java kodu
/* Java implementation to convert an infix expression to postfix*/ // Note that here we use Stack class for Stack operations import java.util.Stack; class Test { // A utility function to return precedence of a given operator // Higher returned value means higher precedence static int Prec(char ch) { switch (ch) { case '+': case '-': return 1; case '*': case '/': return 2; case '^': return 3; } return -1; } // The main method that converts given infix expression // to postfix expression. static String infixToPostfix(String exp) { // initializing empty String for result String result = new String(""); // initializing empty stack Stack<Character> stack = new Stack<>(); for (int i = 0; i<exp.length(); ++i) { char c = exp.charAt(i); // If the scanned character is an operand, add it to output. if (Character.isLetterOrDigit(c)) result += c; // If the scanned character is an '(', push it to the stack. else if (c == '(') stack.push(c); // If the scanned character is an ')', pop and output from the stack // until an '(' is encountered. else if (c == ')') { while (!stack.isEmpty() && stack.peek() != '(') result += stack.pop(); if (!stack.isEmpty() && stack.peek() != '(') return "Invalid Expression"; // invalid expression else stack.pop(); } else // an operator is encountered { while (!stack.isEmpty() && Prec(c) <= Prec(stack.peek())){ if(stack.peek() == '(') return "Invalid Expression"; result += stack.pop(); } stack.push(c); } } // pop all the operators from the stack while (!stack.isEmpty()){ if(stack.peek() == '(') return "Invalid Expression"; result += stack.pop(); } return result; } // Driver method public static void main(String[] args) { String exp = "a+b*(c^d-e)^(f+g*h)-i"; System.out.println(infixToPostfix(exp)); } }
Çıxış:
abcd^e-fgh*+^*+i-
