SlideShare a Scribd company logo
Microsoft® Small BasicStacks and ArraysEstimated time to complete this lesson: 1 hour
Stacks and ArraysIn this lesson, you will learn about:Using different operations of the Stack object.Using different operations of the Array object.
Stacks and ArraysBefore 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 ObjectSo 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 ObjectYou 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.Now, let’s discuss some operations of the Array object, such as IsArray, ContainsIndex, and ContainsValue.
Operations of the Array ObjectAs 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.Let’s see how we can use these operations in a program.output
Operations of the Array ObjectLook 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 Array object also provides more useful operations, such as:  GetAllIndices
GetItemCountThe Stack ObjectLet’s explore each of these 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.The Stack object consists of three operations: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).PushValuePopValueGetCount
 Operations of the Stack ObjectThe 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 ObjectIn 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 write a program to better understand these operations.
Let’s Summarize…Congratulations! Now you know how to: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.

More Related Content

PPTX
3.3 the math object
DOCX
Ecet 370 week 1 lab
PPT
SD & D Arithmetic Operators
DOCX
electic mashinary fundamentals 5th edition Lab tasks stack
PDF
Writea program that defines a template function named add(). Thisfunction tak...
DOC
Cmis 102 hands on/tutorialoutlet
PPTX
Operators in mule dataweave
PPTX
Ml study notes id3
3.3 the math object
Ecet 370 week 1 lab
SD & D Arithmetic Operators
electic mashinary fundamentals 5th edition Lab tasks stack
Writea program that defines a template function named add(). Thisfunction tak...
Cmis 102 hands on/tutorialoutlet
Operators in mule dataweave
Ml study notes id3

What's hot (20)

PPTX
Data structures and algorithms lab9
PPTX
Essential NumPy
DOCX
Cosc 2425 project 2 part 1 implement the following c++ code
PPT
Ppt lesson 11
PPTX
6nullables in c#
PPTX
Insertion sort
PPTX
Stack application
PPT
PPSX
Data Structure (Stack)
PDF
Assignment in java
PPTX
Data Analysis packages
PDF
Algorithm and Data Structure - Queue
PDF
Algorithm and Data Structure - Stack
PDF
Tech Talk - JPA and Query Optimization - publish
PPTX
Java Arrays and DateTime Functions
PDF
C programming exercises and solutions
PDF
Priority Queue
PPTX
Stack Data Structure
PPTX
Function BPK2
DOCX
Ecet 370 week 2 lab 2
Data structures and algorithms lab9
Essential NumPy
Cosc 2425 project 2 part 1 implement the following c++ code
Ppt lesson 11
6nullables in c#
Insertion sort
Stack application
Data Structure (Stack)
Assignment in java
Data Analysis packages
Algorithm and Data Structure - Queue
Algorithm and Data Structure - Stack
Tech Talk - JPA and Query Optimization - publish
Java Arrays and DateTime Functions
C programming exercises and solutions
Priority Queue
Stack Data Structure
Function BPK2
Ecet 370 week 2 lab 2
Ad

Viewers also liked (6)

PPTX
4.2 responding to events
PPTX
3.6 debugging aids
PPTX
4.1 playing with shapes
PPTX
4.4 advanced games
PPTX
5.1 sharing code
PDF
Mlp_winter-2015
4.2 responding to events
3.6 debugging aids
4.1 playing with shapes
4.4 advanced games
5.1 sharing code
Mlp_winter-2015
Ad

Similar to 3.2 stacks and arrays (20)

PPTX
Understanding of Arrays and its types along with implementation
PDF
1-Intoduction ------------- Array in C++
PPTX
Data structures and algorithms arrays
PPTX
Any Which Array But Loose
PPTX
Data Structures - Array presentation .pptx
PPT
Data Structures: A Foundation for Efficient Programming
PDF
DSA-Lecture-05
PPTX
unit 2.pptx
PPTX
ADVANCED DATA STRUCTURES AND ALGORITHMS.pptx
PPT
Lecture 2a arrays
PDF
M v bramhananda reddy dsa complete notes
PPTX
JavaScript.pptx
PDF
LectureNotes-05-DSA
DOCX
Datastructures and algorithms prepared by M.V.Brehmanada Reddy
ODP
C++ arrays part1
PPTX
TMK_DSA_Unit 2 part1(array and stack).pptx
PPTX
introduction of Data strutter and algirithm.pptx
PPTX
Array 1D.................................pptx
PPT
Savitch ch 07
PPT
Ppt lesson 12
Understanding of Arrays and its types along with implementation
1-Intoduction ------------- Array in C++
Data structures and algorithms arrays
Any Which Array But Loose
Data Structures - Array presentation .pptx
Data Structures: A Foundation for Efficient Programming
DSA-Lecture-05
unit 2.pptx
ADVANCED DATA STRUCTURES AND ALGORITHMS.pptx
Lecture 2a arrays
M v bramhananda reddy dsa complete notes
JavaScript.pptx
LectureNotes-05-DSA
Datastructures and algorithms prepared by M.V.Brehmanada Reddy
C++ arrays part1
TMK_DSA_Unit 2 part1(array and stack).pptx
introduction of Data strutter and algirithm.pptx
Array 1D.................................pptx
Savitch ch 07
Ppt lesson 12

More from allenbailey (15)

PPTX
4.3 collision detection
PPTX
3.5 the controls object
PPTX
3.4 events and interactivity
PPTX
3.1 file input and output
PPTX
2.6 flickr, image list, and network objects
PPTX
2.5 clock, desktop, and dictionary objects
PPTX
2.4 sound, program, and text objects
PPTX
2.3 exploring shapes
PPTX
2.2 turtle graphics
PPTX
2.1 graphics window
PPTX
1.5 branching and subroutines
PPTX
1.4 conditions and loops
PPTX
1.3 variables
PPTX
1.2 statements, properties, and operations
PPTX
1.1 introduction to small basic
4.3 collision detection
3.5 the controls object
3.4 events and interactivity
3.1 file input and output
2.6 flickr, image list, and network objects
2.5 clock, desktop, and dictionary objects
2.4 sound, program, and text objects
2.3 exploring shapes
2.2 turtle graphics
2.1 graphics window
1.5 branching and subroutines
1.4 conditions and loops
1.3 variables
1.2 statements, properties, and operations
1.1 introduction to small basic

Recently uploaded (20)

PDF
Western Pop Music: From Classics to Chart-Toppers
PPTX
the Honda_ASIMO_Presentation_Updated.pptx
PDF
What is Rotoscoping Best Software for Rotoscoping in 2025.pdf
PPTX
wegen seminar ppt.pptxhkjbkhkjjlhjhjhlhhvg
PDF
Gess1025.pdfdadaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
PPTX
just letters randomized coz i need to up
PPTX
continuous_steps_relay.pptx. Another activity
PPTX
Hacking Movie – Best Films on Cybercrime & Digital Intrigue
PDF
High-Quality PDF Backlinking for Better Rankings
PDF
WKA #29: "FALLING FOR CUPID" TRANSCRIPT.pdf
PDF
A New Kind of Director for a New Kind of World Why Enzo Zelocchi Matters More...
PPTX
the-solar-system.pptxxxxxxxxxxxxxxxxxxxx
PDF
MAGNET STORY- Coaster Sequence (Rough Version 2).pdf
PPTX
Safety_Pharmacology_Tier2_Edibbbbbbbbbbbbbbbable.pptx
PDF
Benben maam tess of the report on somthing
PPTX
BULAN K3 NASIONAL PowerPt Templates.pptx
PDF
Rakshabandhan – Celebrating the Bond of Siblings - by Meenakshi Khakat
PDF
EVs U-5 ONE SHOT Notes_c49f9e68-5eac-4201-bf86-b314ef5930ba.pdf
DOCX
Nina Volyanska Controversy in Fishtank Live_ Unraveling the Mystery Behind th...
PDF
TAIPANQQ SITUS MUDAH MENANG DAN MUDAH MAXWIN SEGERA DAFTAR DI TAIPANQQ DAN RA...
Western Pop Music: From Classics to Chart-Toppers
the Honda_ASIMO_Presentation_Updated.pptx
What is Rotoscoping Best Software for Rotoscoping in 2025.pdf
wegen seminar ppt.pptxhkjbkhkjjlhjhjhlhhvg
Gess1025.pdfdadaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
just letters randomized coz i need to up
continuous_steps_relay.pptx. Another activity
Hacking Movie – Best Films on Cybercrime & Digital Intrigue
High-Quality PDF Backlinking for Better Rankings
WKA #29: "FALLING FOR CUPID" TRANSCRIPT.pdf
A New Kind of Director for a New Kind of World Why Enzo Zelocchi Matters More...
the-solar-system.pptxxxxxxxxxxxxxxxxxxxx
MAGNET STORY- Coaster Sequence (Rough Version 2).pdf
Safety_Pharmacology_Tier2_Edibbbbbbbbbbbbbbbable.pptx
Benben maam tess of the report on somthing
BULAN K3 NASIONAL PowerPt Templates.pptx
Rakshabandhan – Celebrating the Bond of Siblings - by Meenakshi Khakat
EVs U-5 ONE SHOT Notes_c49f9e68-5eac-4201-bf86-b314ef5930ba.pdf
Nina Volyanska Controversy in Fishtank Live_ Unraveling the Mystery Behind th...
TAIPANQQ SITUS MUDAH MENANG DAN MUDAH MAXWIN SEGERA DAFTAR DI TAIPANQQ DAN RA...

3.2 stacks and arrays

  • 1. Microsoft® Small BasicStacks and ArraysEstimated time to complete this lesson: 1 hour
  • 2. Stacks and ArraysIn this lesson, you will learn about:Using different operations of the Stack object.Using different operations of the Array object.
  • 3. Stacks and ArraysBefore 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.
  • 4. The Array ObjectSo 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!
  • 5. Operations of the Array ObjectYou 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.Now, let’s discuss some operations of the Array object, such as IsArray, ContainsIndex, and ContainsValue.
  • 6. Operations of the Array ObjectAs 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.Let’s see how we can use these operations in a program.output
  • 7. Operations of the Array ObjectLook 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 Array object also provides more useful operations, such as:  GetAllIndices
  • 8. GetItemCountThe Stack ObjectLet’s explore each of these 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.The Stack object consists of three operations: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).PushValuePopValueGetCount
  • 9. Operations of the Stack ObjectThe 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.
  • 10. Operations of the Stack ObjectIn 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 write a program to better understand these operations.
  • 11. Let’s Summarize…Congratulations! Now you know how to:Use different operations of the Stack object.Use different operations of the Array object.
  • 12. 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.
  • 13. Display the seat number of the passenger along with his or her name.
  • 14. Display the total number of seats available.

Editor's Notes

  • #7: Code:Subjects[1] = "English"Subjects[2] = "History"Subjects[3] = "Computers"Subjects[4] = "Science"Subjects[5] = "Math“TextWindow.WriteLine("Subjects is an array: " + Array.IsArray(Subjects))TextWindow.WriteLine("Subjects[4] is available: " + Array.ContainsIndex(Subjects, 4))TextWindow.WriteLine("Math is available: " + Array.ContainsValue(Subjects, "Math"))Array.GetItemCount(Subjects)
  • #10: Slide Notes:The PushValue operation does not return anything.The PopValue operation returns the value from the stack.The GetCount operation returns the number of items in a specified stack.
  • #11: Code:container = "empty"For i = 0 To 50 Stack.PushValue(container , "plate number " + i) EndForTextWindow.WriteLine("The number of plates in the container is " + Stack.GetCount(container))For i = 0 To 8Stack.PopValue(container) EndForTextWindow.WriteLine("After taking away 8 plates, the total number of plates is " + Stack.GetCount(container))TextWindow.WriteLine("The top most plate in the container is " + Stack.PopValue(container))
  • #13: Solution:TextWindow.WriteLine(“Flight Reservations")TotalSeats = 10For i = 1 To TotalSeatsTextWindow.Write("Enter Passenger Name: ") Name[i] = TextWindow.Read() TextWindow.WriteLine("Seat number " + i + " is reserved by " + Name[i])GetDetails()EndForSub GetDetailsIf Array.GetItemCount(Name) = TotalSeats ThenTextWindow.WriteLine("No more seats are available!")ElseArray.GetItemCount(Name)AvailableSeats = TotalSeats - Array.GetItemCount(Name) TextWindow.WriteLine("Number of available seats is: " + AvailableSeats)TextWindow.WriteLine("") EndIfEndSub