int main() { char symbol; StackType stack; bool balanced = true; char openSymbol; cout << "Enter an expression and press return." << endl; cin.get(symbol); while (symbol != '\n' && balanced) { if (IsOpen(symbol)) stack.Push(symbol); else if (IsClosed(symbol)) { if (stack.IsEmpty()) balanced = false; else { openSymbol = stack.Top(); stack.Pop(); balanced = Matches(symbol, openSymbol); } } cin.get(symbol); } if (balanced) cout << "Expression is well formed." << endl; else cout << "Expression is not well formed." << endl; return 0; }
int main() { bool palindrome = true; char character; StackType stack; QueType queue(40); char stackChar; char queChar; cout << "Enter a string; press return." << endl; cin.get(character); while (character != '\n') { stack.Push(character); queue.Enqueue(character); cin.get(character); } while (palindrome && !queue.IsEmpty()) { stackChar = stack.Top(); stack.Pop(); queue.Dequeue(queChar); if (stackChar != queChar) palindrome = false; } if (palindrome) cout << "String is a palindrome" << endl; else cout << "String is not a palindrome" << endl; return 0; }
// Reads and executes commmands from queriesfile.txt void readqueries(StackType& email, ifstream& in){ char command[30], address[50]; int k; while (!(in.eof())) { in >> command; if (strcmp(command,"LIST-MESSAGES-BY-DATE") == 0) email.Report(); if (strcmp(command,"LIST-MESSAGES-FROM") == 0){ in>>address; email.ReportfromSender(address); } if (strcmp(command,"DELETE-MOST-RECENT-MESSAGE") == 0) email.Pop(); if (strcmp(command,"DISPLAY") == 0 ){ in >> k; email.Get(k); }