{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

# Project 1 - CS352 Data Structures Winter/Spring 2007...

This preview shows pages 1–2. Sign up to view the full content.

CS352 Data Structures Winter/Spring 2007 Project 1: Stack Sorting Section V0A 2:00 pm Thursday, Feb. 15, 2007 Section V0B 5:30 pm Thursday, Feb. 15, 2007 Motivation Suppose that some permutation of integers 1,2,3,. ..,n-1,n is given as input. It might be possible to sort them into the correct order by using two stacks with only the following operations allowed: stack1.push(inputValue) stack2.push(inputValue) stack2.push(stack1.pop()) output(stack1.pop()) output(stack2.pop()) Suppose the input is 3, 2, 1. Then the following operations would sort the sequence: stack1.push(3) stack2.push(2) output(1) output(pop(stack2)) output(pop(stack1)) Of course, this particular sequence could also be sorted using only one stack. Note:During the sorting process: an element from the input sequence can either be output or pushed into one of the stacks. 1. An element in stack1 can be popped and pushed into stack2, but no elements in stack2 can be popped and pushed into stack1 2. Problem Specification For this project, you must design and implement an algorithm (with supporting abstract data structures, in an algorithmic language) that might be used to sort given input sequences using two stacks as described. It might be the case that some sequences can be sorted in this way, but some cannot. Your algorithm must determine when to stop processing an input sequence. This will occur either when the sequence is successfully sorted, or when it is determined that the input cannot be sorted by the stack. Test your algorithm and hand-simulate it to convince yourself it is correct. Analyze your algorithm for time complexity (best- and worst-case). Then implement your algorithm. At this time (and not any earlier) decide

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 4

Project 1 - CS352 Data Structures Winter/Spring 2007...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online