{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

CSC-113-Lab 13 - pop X and dequeue B and detect that the...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
KSU / CCIS / CS DEPARTMENT CSC-113, SPRING 2010 LAB 13 STACKS/QUEUES Exercise 2. (Stack & Queue) One type of application that uses both a stack and a queue is a palindrome checker, which determines whether the input stream reads the same backwards as forwards. One strategy is to store the input both in a stack and in a queue. Then we read the stack items (representing the input in reverse order) and the queue items (the sequence in the original order). If they match, then the input is palindromic. Write a Java program that uses both a stack and queue to test if a given string is palindrome or not. For example, suppose that the input is the seven-character stream A B C D C X A Figure 1 shows the stack after the reading phase and Figure 2 shows the queue (head to the left as usual). Figure 2 shows the stack and queue after one iteration of the checking loop. As you can see, the next iteration will
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: pop X and dequeue B , and detect that the input is not a palindrome. (a) (b) Fig 1. Stack (a) and queue (b) after reading ABCDCXA (b) (a) Fig 2. Stack (a) and queue (b) after one iteration of checking loop Exercise 1. (Linked list & Stack) Write a Java program that uses a stack to test for balanced pairs of various types of brackets (), , <> or {}. The input consists of two linked lists of characters including opened brackets (, [, <, {and closed brackets ), ], >, }. An expression is correctly parenthesized if each left bracket is matched with a right bracket of the same type. So that: {abc<2+3>([ef]ghi)} is correct {abc<2+3>([ef)ghi]} is incorrect Your program will read an expression and determine if it’s correct or not. For a given expression, your program should print “correct” or “incorrect”. A B A X C D C A X C D C B A X C D C B A B A X C D C...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online