Tidily
Tidily
Sayfa 1 / 4
Q3 Here is an INCORRECT pseudocode for the algorithm which is supposed to determine whether a
sequence of parentheses is balanced:
declare a character stack
while ( more input is available)
{
read a character
if the character is a '('
push it on the stack
else if the character is a ')' and the stack is not empty
pop a character off the stack
else
print "unbalanced" and exit
}
print "balanced"
Which of these unbalanced sequences does the above code think is balanced?
a) ((())
b) ())(()
c) (()()))
d) (()))()
Q4 Here is an infix expression: 4+3*(6*3-12). Suppose that we are using the usual Stack algorithm to
convert the expression from infix to postfix notation. What is the maximum number of symbols that
will appear on the stack AT ONE TIME during the conversion of this expression?
a) 1
b) 2
c) 3
d) 4
e) 5
Info Link
Head 0 C 6
3 1 B 0
2 5
3 A 1
Avail 4 F -1
2 5 -1
6 D 7
7 E 4 Info Link
Head 0
1
2
3
Avail 4
5
6
7
1. Find the sequence of characters in the list.(5 P)
2. Suppose Z is inserted at the beginin of the list later F then C are deleted from the list
and G is inserted at the beginning of the list. Find the final structure.(Use following
figure to give your answer) (10p)
Sayfa 2 / 4
Q2) A palindrome is a string that reads the same both forward and backward. For
example
"bob" "otto" "1991" "x" "live dual - laud evil" are all palindromes, but "teeth" is not.
Write a C function that takes a string as an argument and (1) if the string is a
palindrome prints it and returns 1 else (2) returns 0. Use this function to write a
program that will accept a sequence of lines, print those that are palindromes, and
finally print the number of palindromes found. (10p)
Q3) Give the contents of the stack after each operation in the sequence
EAS*Y**QUE***ST***I*ON**
Here a letter means “push" the letter, and “*" means “pop." (20p)
Sayfa 3 / 4
Part III (Solve Only ONE question)
Q4) Write a function that takes a char queue q as an argument, where the queue contains a selection of
symbols “a,………,z” and some ‘+’ symbols. The function should print to the screen the two
characters that precede (come before) every occurrence of ‘+’ in the queue. For example, if q
contains {a,b,c,+,e,e,e,+,f,g,+,p} then “cbeegf” should be printed to the screen. Assume that at least
2 alphabet symbols precede each ‘+’ symbol. (use only valid queue operations) (45 P)
a b c + e e e + f g + p
Front Rear
Q5) Consider the following queue. Write a function to remove the repeated symbols from queue.
Don’t use array(Assume queue operations isEmpty, delete, and append are available)
(35P)Consider following example, If input Queue is;
1 1 4 1 1 2 8 3 8 9 9 9 7 5 9 7 0 6 5 3 9
Fron Rea
t r
4 2 0 6
Front Rear
Sayfa 4 / 4