////zie Blackboard voor opdrachten uitleg //Palindrome checker. //Schrijf een methode (Paldindroom) die gegeven een string bekijkt of het een palindroom betreft. //Leestekens, spaties en case (kleine of hooddletters) moet je negeren. //gebruik 1 Stack en 1 Queue. //tip: itereer 1 keer door de string! //De voorbeeld palindromen: http://home.wxs.nl/~avdw3b/palindr.html public bool Palindroom(string input) { IStack <char> s = StackFactory.CreateStack <char>(); IQueue <char> q = QueueFactory.CreateQueue <char>(); throw new NotImplementedException(); }
//opgave 1 public static bool CheckParenthesis(string input) { IStack <char> par = StackFactory.CreateStack <char>(); if (input == null) { return(true); } foreach (char karakter in input) { if (openParenthesis.Contains(karakter)) { par.Push(karakter); } if (closeParenthesis.Contains(karakter)) { int index = closeParenthesis.IndexOf(karakter); char c = openParenthesis[index]; if (par.Peek() == c) { par.Pop(); } else { return(false); } } } return(par.Count == 0); }
////zie Blackboard voor opdrachten uitleg //Palindrome checker. //Schrijf een methode (Paldindroom) die gegeven een string bekijkt of het een palindroom betreft. //Leestekens, spaties en case (kleine of hooddletters) moet je negeren. //gebruik 1 Stack en 1 Queue. //tip: itereer 1 keer door de string! //De voorbeeld palindromen: http://home.wxs.nl/~avdw3b/palindr.html public bool Palindroom(string input) { List <char> ignore = new List <char> { ' ', '.', ',', '\'' }; IStack <char> s = StackFactory.CreateStack <char>(); IQueue <char> q = QueueFactory.CreateQueue <char>(); if (input == null) { return(false); } input = input.ToLower(); foreach (char karakter in input) { if (!ignore.Contains(karakter)) { s.Push(karakter); q.Enqueue(karakter); } } if (s.Count == 0) { return(false); } for (int i = 0; i < s.Count; i++) { if (s.Pop() != q.Dequeue()) { return(false); } } return(true); }
//zie Blackboard voor opdrachten uitleg // 1+5=6 wordt 1 5 + :6 public static int PostFixEvaluation(string postfix) { IStack <int> stack = StackFactory.CreateStack <int>(); int y = 0; int x = 0; int result = 0; foreach (char karakter in postfix) { if (karakter != ' ') { if (char.IsDigit(karakter)) { stack.Push((int)char.GetNumericValue(karakter)); } else { y = stack.Pop(); x = stack.Pop(); if (karakter == '*') { result = x * y; } if (karakter == '/') { result = x / y; } if (karakter == '+') { result = x + y; } if (karakter == '-') { result = x - y; } stack.Push(result); } } } return(stack.Pop()); }
//opgave 1 public static bool CheckParenthesis(string input) { IStack <char> par = StackFactory.CreateStack <char>(); throw new NotImplementedException(); }
}; //zie https://en.wikipedia.org/wiki/Order_of_operations public static string ToPostfix(string infix) { IStack <string> op = StackFactory.CreateStack <string>(); throw new NotImplementedException(); }
//zie Blackboard voor opdrachten uitleg public static int PostFixEvaluation(string postfix) { IStack <int> stack = StackFactory.CreateStack <int>(); throw new NotImplementedException(); }