Microsoft® Small Basic Stacks and Arrays Estimated time to complete this lesson: 1 hour.

Slides:



Advertisements
Similar presentations
STACKS & QUEUES. Stacks Abstract data types An abstract data type (ADT) is an abstraction of a data structure An ADT specifies : –Data stored –Operations.
Advertisements

Microsoft® Small Basic
Stacks  a data structure which stores data in a Last-in First-out manner (LIFO)  has a pointer called TOP  can be implemented by either Array or Linked.
CS 206 Introduction to Computer Science II 03 / 04 / 2009 Instructor: Michael Eckmann.
Linked Lists Compiled by Dr. Mohammad Alhawarat CHAPTER 04.
Programming with Alice Computing Institute for K-12 Teachers Summer 2011 Workshop.
Stacks A stack is a data structure that only allows items to be inserted and removed at one end We call this end the top of the stack The other end is.
Stacks. What is a stack? Last-in first-out data structure (LIFO) New objects are placed on top Removal restricted to top object Examples?
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Java Software Solutions Foundations of Program Design Sixth Edition by Lewis.
CS 206 Introduction to Computer Science II 10 / 26 / 2009 Instructor: Michael Eckmann.
Stacks. 2 Outline and Reading The Stack ADT (§2.1.1) Array-based implementation (§2.1.1) Growable array-based stack (§1.5) Java.util.Stack class Java.util.Vector.
1 Data Structures  We can now explore some advanced techniques for organizing and managing information  Chapter 12 of the book focuses on: dynamic structures.
Implementing Stacks Using Arrays CSC 1401: Introduction to Programming with Java Week 14 – Lecture 1 Wanda M. Kunkle.
Chapter 12 Collections. © 2004 Pearson Addison-Wesley. All rights reserved12-2 Collections A collection is an object that helps us organize and manage.
30-Jun-15 Stacks. What is a stack? A stack is a Last In, First Out (LIFO) data structure Anything added to the stack goes on the “top” of the stack Anything.
Liang, Introduction to Java Programming, Tenth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 20 Lists, Stacks, Queues, and Priority.
© 2004 Pearson Addison-Wesley. All rights reserved12-1 Chapter 12 : Collections Intermediate Java Programming Summer 2007.
Data Structures Data structures permit the storage of related data for use in your program. –Arrays.
Microsoft® Small Basic
Ali Abdul Karem Habib Kufa University / mathematics & Science Of Computer.
Microsoft® Small Basic The Controls Object Estimated time to complete this lesson: 1 hour.
Microsoft® Small Basic
Stack Data Structure By : Imam M Shofi. What is stack? A stack is a limited version of an array. A stack is a limited version of an array. New elements,
Week7 Stack Data Structures & Algorithms. Introduction to Stacks and Queues Widely used data structures Ordered List of element Easy to implement Easy.
CHAPTER 05 Compiled by: Dr. Mohammad Omar Alhawarat Stacks & Queues.
© 2006 Pearson Education Chapter 12: Data Structures Presentation slides for Java Software Solutions for AP* Computer Science A 2nd Edition by John Lewis,
Stacks and Queues Introduction to Computing Science and Programming I.
Data Structures in Python By: Christopher Todd. Lists in Python A list is a group of comma-separated values between square brackets. A list is a group.
Python November 28, Unit 9+. Local and Global Variables There are two main types of variables in Python: local and global –The explanation of local and.
First tutorial.
Stack. Abstract Data Types (ADTs) An abstract data type (ADT) is an abstraction of a data structure An ADT specifies: Data stored Operations on the data.
Week 7. Lecture 2 Functions, Arrays, PHP&MySQL. Function with More than one argument and a return statement For a function to return a value, the return.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 18: Stacks and Queues (part 3)
Stacks. A stack is a data structure that holds a sequence of elements and stores and retrieves items in a last-in first- out manner (LIFO). This means.
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 18 Stacks and Queues.
1 Mr. Muhammad Hanif Lecturer Information Technology MBBS Campus Dadu University of SIndh.
Data structures Abstract data types Java classes for Data structures and ADTs.
A data structure is a type of data storage ….similar to an array. There are many data structures in Java (Stacks, Queues, LinkedList, Sets, Maps, HashTables,
COP INTERMEDIATE JAVA Data Structures. A data structure is a way of organizing a collection of data so that it can be manipulated effectively. A.
Understanding Data Types and Collections Lesson 2.
Chapter 12: Collections by Lewis and Loftus (Updated by Dan Fleck) Coming up: Collections.
EASTERN MEDITERRANEAN UNIVERSITY Stacks EENG212 –Algorithms and Data Structures.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 18: Stacks and Queues.
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 19: Stacks and Queues.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 18: Stacks and Queues.
Stacks And Queues Chapter 18.
Scis.regis.edu ● CS-362: Data Structures Week 8 Dr. Jesús Borrego 1.
Project 1: Using Arrays and Manipulating Strings Essentials for Design JavaScript Level Two Michael Brooks.
Chapter 4 Stacks and Queues © 2006 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved.
Data Structures David Kauchak cs302 Spring Data Structures What is a data structure? Way of storing data that facilitates particular operations.
Stacks and Queues CMSC 201. Stacks and Queues Sometimes, when we use a data-structure in a very specific way, we have a special name for it. This is to.
STACK Data Structure
CSE 373 Data Structures and Algorithms Lecture 1: Introduction; ADTs; Stacks; Eclipse.
Lecture 21 Data Structures, Algorithms and Complexity Stacks and Queues GRIFFITH COLLEGE DUBLIN.
M180: Data Structures & Algorithms in Java Stacks Arab Open University 1.
Stack. ADS2 Lecture 1010 The Stack ADT (GoTa §5.1) The Stack ADT stores arbitrary objects Insertions and deletions follow the last-in.
Stacks. What is a Stack? A stack is a type of data structure (a way of organizing and sorting data so that it can be used efficiently). To be specific,
Microsoft® Small Basic Conditions and Loops Estimated time to complete this lesson: 2 hours.
Click to edit Master text styles Stacks Data Structure.
1 Data Structures CSCI 132, Spring 2016 Notes_ 5 Stacks.
Stack: a Linked Implementation
Stacks and Queues.
STACK CHAPTER 03 Developed By :- Misha Ann Alexander Data Structures.
Visit for more Learning Resources
Starter Write a program that asks the user if it is raining today.
COMPUTER 2430 Object Oriented Programming and Data Structures I
Pointers and Linked Lists
Stacks Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013.
Tonga Institute of Higher Education
COMPUTER 2430 Object Oriented Programming and Data Structures I
Presentation transcript:

Microsoft® Small Basic Stacks and Arrays Estimated time to complete this lesson: 1 hour

Stacks and Arrays In this lesson, you will learn about: Using different operations of the Stack object.Using different operations of the Array object.

Stacks and Arrays Before we move on to discuss the Array object and the Stack object, let’s first understand when we use both of these objects. Arrays can be multi-dimensional, but a stack is only one-dimensional. You can use arrays to directly access any of its elements but if you use a stack, you can access only the top element. For instance, if you want to access the last element of the stack, you must go through all the elements from the beginning.

The Array Object So far, you have learned about variables that store single values. Now, let’s learn about a special variable called an Array. An array is a type of variable that can store multiple values at a time. If you want to store the names of five users, then instead of creating different variables, you can just use one variable to store all of the five names. You use the indexing method to store multiple values in an array. For example, you can create an array called name as: name[1], name[2], name[3], name[4], and name[5]. Here, 1, 2, 3, 4, and 5 are the indices for the name array. The name[1], name[2]… may seem to you as different variables, but they are all just one variable!

Operations of the Array Object Now, let’s discuss some operations of the Array object, such as IsArray, ContainsIndex, and ContainsValue. You can use the IsArray operation to check whether the specified variable is an array. You can use the ContainsIndex operation to check whether the array contains the specified index. This operation is helpful when you want to check whether the array’s index is initialized by a specific value. You can use the ContainsValue operation to check whether the array contains the specified value. You can use this operation to check if the array’s value was stored in the specified index.

Operations of the Array Object Let’s see how we can use these operations in a program. As you can see, Subjects as an array stores the names of five different subjects. You can use the IsArray operation to check if Subjects is an array. You can also use the ContainsIndex operation to check the availability of the index Subjects[4] in the Subjects array. Lastly, you can use the ContainsValue operation to see if the value “Math” is available in the Subjects array.

Operations of the Array Object The Array object also provides more useful operations, such as:  GetAllIndices  GetItemCount Look at this example to learn how to use these operations. In this example, because you don’t know the indices for the Employee array, you use the GetAllIndices operation. Next, you use the GetItemCount operation in a For loop to list the information stored in the Employee array.

The Stack Object The Stack object in Small Basic is a method of storing data in the manner of stacking of plates. It works on the principle of last-in, first-out (LIFO). The Stack object consists of three operations: For example, if you look down at a stack of plates, you can only see the top plate. To see the next plate, you will have to remove this top plate. You can’t pick a plate from the middle of the stack until you’ve removed the plates above it. PushValuePopValue GetCount Let’s explore each of these operations…

Operations of the Stack Object The Stack object stores data just as a stack of plates. Let’s take a look at some examples to understand how it works. The PushValue operation is like adding a new plate to the top of the stack of plates. With the help of this operation, you can push a value to the specified stack. The PopValue operation is like picking out a plate from the top of the stack. You can use this operation to pop out a value from the specified stack. The GetCount operation provides the total number of plates in the stack. You can use this operation to determine the count of items in a specified stack.

Operations of the Stack Object Let’s write a program to better understand these operations. In this example, you use the PushValue operation to push 50 plates into an empty container. Then by using the PopValue operation, you take eight plates away from the stack. Now, use the GetCount operation to get the total number of plates in the container. You also display the value of the plate, which is placed at the top.

Let’s Summarize… Congratulations! Now you know how to: Use different operations of the Stack object. Use different operations of the Array object. Use different operations of the Stack object. Use different operations of the Array object.

It’s Time to Apply Your Learning… Using the Array object, write a program for “Flight Reservation” that allows you to perform the following actions:  Reserve seats for 10 passengers.  Display the seat number of the passenger along with his or her name.  Display the total number of seats available.