联系方式

  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-23:00
  • 微信:codinghelp

您当前位置:首页 >> Java编程Java编程

日期:2019-02-28 09:30

CSC 115 - Lab#6 Stacks

Objectives

During Lab#6, week, you will be completing a programming exercise that you will hand in

through conneX. You will learn:

How to implement common operations related to Stacks based on a singly-linked list.

How to solve a practical problem using a Stack.

How to build a tester and debug your codes in Java.

Required files

You will need to hand in two java files that you complete:

Stack.java

BracketBalance.java

The following files are provided as helper files:

Node.java

Tester.java

Stack Review

Though we usually line up as a Queue to pay our groceries in stores, we use Stack unconsciously

daily: surfing the internet using browsers, when we go back to the previous page, we

click on the <= button. The websites that we have just visited are actually stored in a Stack.

A Stack is an abstract data type which is used to store a collection of data. It has the property

that the last item placed on the stack will be the first item removed. The property is referred

to as Last-in, first-out (LIFO). Common operations related to Stack are:

empty - check if the stack is empty

push (item) - push the item on to the stack

peek - check what is on top of the stack. The stack is not changed.

pop - remove the item at the top of the stack. The stack is reduced by one.

Your Task: Download Stack.java and implement the methods. Notice that the Node class

Page 1 of 2

will be used in Stack class and you should download this file as well.

Stack Application - Bracket Balancing

Stack is very useful to check if braces are balanced in mathematic expressions. The algorithm

can be:

For a sequence of characters

If there is an open brace “{”, or bracket “(”, or square bracket “[”, then push it onto the stack;

If there is an closing brace “}”, or bracket “)”, or square bracket “]”, then:

If the stack is empty, then it is not balanced

Else

Pop the stack;

If the popped character is not the matching open brace/bracket/square-bracket, then

the sequence is not balanced.

After the sequence is processed, it is safe to say that it is balanced.

Your Task: Download BracketBalance.java and finish the implementation.

The Test.java program will give a Pass or Fail depending on the automated test results. Note

that a Pass is not an indication that everything is perfect, the intention is to reward effort, and

give enough feedback so you can seek guidance if you see that you can benefit from it.

Document created by: Tianming Wei on February 25, 2019


版权所有:留学生编程辅导网 2020 All Rights Reserved 联系方式:QQ:99515681 微信:codinghelp 电子信箱:99515681@qq.com
免责声明:本站部分内容从网络整理而来,只供参考!如有版权问题可联系本站删除。 站长地图

python代写
微信客服:codinghelp