Arrays and Collections Tonga Institute of Higher Education.

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

Stacks and Queues. Not really data structures – More of an enforcement of policy – Can be implemented using an array or linked list – Can store just about.
Data Structures Lecture 13: QUEUES Azhar Maqsood NUST Institute of Information Technology (NIIT)
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.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 18: Stacks And Queues.
Copyright © 2012 Pearson Education, Inc. Chapter 18: Stacks And Queues.
Data Structures Michael J. Watts
CS 106 Introduction to Computer Science I 12 / 06 / 2006 Instructor: Michael Eckmann.
CS 206 Introduction to Computer Science II 10 / 17 / 2008 Instructor: Michael Eckmann.
CS 206 Introduction to Computer Science II 10 / 20 / 2008 Instructor: Michael Eckmann.
CS 104 Introduction to Computer Science and Graphics Problems Data Structure & Algorithms (4) Data Structures 11/18/2008 Yang Song.
CS 106 Introduction to Computer Science I 12 / 11 / 2006 Instructor: Michael Eckmann.
CS 206 Introduction to Computer Science II 10 / 26 / 2009 Instructor: Michael Eckmann.
1 Data Structures  We can now explore some advanced techniques for organizing and managing information  Chapter 12 of the book focuses on: dynamic structures.
CS 106 Introduction to Computer Science I 12 / 13 / 2006 Instructor: Michael Eckmann.
CS 206 Introduction to Computer Science II 10 / 28 / 2009 Instructor: Michael Eckmann.
© 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.
Review C++ exception handling mechanism Try-throw-catch block How does it work What is exception specification? What if a exception is not caught?
90-723: Data Structures and Algorithms for Information Processing Copyright © 1999, Carnegie Mellon. All Rights Reserved. 1 Lecture 5: Stacks and Queues.
CHAPTER 05 Compiled by: Dr. Mohammad Omar Alhawarat Stacks & Queues.
Stacks and Queues Introduction to Computing Science and Programming I.
Mastering STACKS AN INTRODUCTION TO STACKS Data Structures.
Adapted from instructor resources Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights.
CS 46B: Introduction to Data Structures July 9 Class Meeting Department of Computer Science San Jose State University Summer 2015 Instructor: Ron Mak
Copyright © 2012 Pearson Education, Inc. Chapter 18: Stacks And Queues.
Chapter 9 (modified) Abstract Data Types and Algorithms Nell Dale John Lewis.
9-1 Abstract Data Types Abstract data type A data type whose properties (data and operations) are specified independently of any particular implementation.
Cosc237/data structures1 Data Types Every data type has two characteristics: 1.Domain - set of all possible values 2.set of allowable operations Built-in.
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 18 Stacks and Queues.
Murach’s Visual Basic 2008, modified, C8© 2008, Mike Murach & Associates, Inc. Slide 1.
Queues Tonga Institute of Higher Education. Definitions Queue - A data structure that stores a number of items. The first item entered into a queue is.
CMSC 202 Stacks and Queues. What’s a Queue? A queue is a linear collection of homogeneous data in which items added to the queue must be placed at the.
Data Structures (part 2). Stacks An Everyday Example Your boss keeps bringing you important items to deal with and keeps saying: “Put that last ‘rush’
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.
Stacks and Queues. 2 3 Runtime Efficiency efficiency: measure of computing resources used by code. can be relative to speed (time), memory (space), etc.
Understanding Data Types and Collections Lesson 2.
Foundation of Computing Systems Lecture 3 Stacks and Queues.
Queue What is a queue?. Queues A queue is similar to waiting in line for a service, e.g., at the bank, at the bathroom –The first item put on the queue.
Stacks And Queues Chapter 18.
Data Structures Types of Data Structure Data Structure Operations Examples Choosing Data Structures Data Structures in Alice.
Data Structures Chapter 6. Data Structure A data structure is a representation of data and the operations allowed on that data. Examples: 1.Array 2.Record.
Chapter 4 Stacks and Queues © 2006 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved.
Understanding General Software Development Lesson 3.
Week 2 - Friday.  What did we talk about last time?  Computing Big Oh.
1 Algorithms Queues, Stacks and Records stored in Linked Lists or Arrays.
ITEC 2620M Introduction to Data Structures Instructor: Prof. Z. Yang Course Website: ec2620m.htm Office: Tel 3049.
COMPUTER PROGRAMMING 2 ArrayLists. Objective/Essential Standard Essential Standard 3.00Apply Advanced Properties of Arrays Essential Indicator 3.02 Apply.
Data-structure-palooza Checkout DataStructures from SVN.
Copyright © Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Java From Control Structures through Data Structures by Tony.
Generics & Collection Classes Version 1.0. Topics Generic Methods and Classes Generic Collection Classes List Enumerators Queue Stack LinkedList.
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.
Understanding General Software Development Lesson 3.
Click to edit Master text styles Stacks Data Structure.
1 Lecture 9: Stack and Queue. What is a Stack Stack of Books 2.
CPS120: Introduction to Computer Science Nell Dale John Lewis Abstract Data Types.
Computing with C# and the .NET Framework
Set Collection A Bag is a general collection class that implements the Collection interface. A Set is a collection that resembles a Bag with the provision.
Lecture 7 Queues Stacks Trees.
COSC160: Data Structures: Lists and Queues
Stacks and Queues.
Array Array is a variable which holds multiple values (elements) of similar data types. All the values are having their own index with an array. Index.
Data Structures and Database Applications Queues in C#
HW-6 Deadline Extended to April 27th
Tonga Institute of Higher Education
Data Structures and Algorithms for Information Processing
Visit for more Learning Resources
Presentation transcript:

Arrays and Collections Tonga Institute of Higher Education

Introduction An array is a data structure. An array holds data. Definitions  Cell/Element – A box in which you can enter a piece of data.  Index – A number identifying the location of the cell Example: 0, 1, 2, 3, 4, 5  Field - A piece of data Example: 23, 11, 2, 35, 4, 43 Once you define the size of an array, you cannot change it

Array Indexes Index – A number identifying the location of the cell Index starts at 0  If your array has 6 cells, the indexes are from 0 to

Creating Arrays You need to declare and create them Or Parenthesis means it’s an array Must define the size when you create them. This has 5 cells. Must state what the array will contain Did not include size Size and data are set here Brackets used for setting values Initial values are “”

Demonstration Creating Arrays

Accessing Data in Arrays Syntax: ( ) Setting Values  arrNames(0) = “Tevita”  arrAges(3) = 5  arrNames(10) = 3  arrNames(2) = 5 Getting Values  MessageBox.Show(arrNames(0))  Dim Age as Integer = arrAges(3) Error: Index is too big. Error: Array can only contain letters.

Demonstration Accessing Data in Arrays

Arrays are Objects Arrays have properties and methods  Length  Clear  Sort  And others But they must be declared and initialized in the previously covered way

Demonstration Array Object

Other Collections Arrays are the most commonly used data structure There are other classes that implement different data structures  ArrayList  SortedList  Queue  Stack  HashTable

ArrayList An array whose size changes automatically as elements are added and removed Methods make it easier to use the array Index management is simplified

Demonstration ArrayList

SortedList A collection that sorts the elements based on a value The sort value can be different from the data stored. This is useful if the object stored has many pieces of data to sort by.

Demonstration SortedList

Queue Queue - A data structure that stores a number of items. The first item entered into a queue is the first item to be removed FIFO – First in First out – Sometimes used to describe a queue Enqueue - The act of adding an item to a queue Dequeue - The act of removing an item from the front of a queue Examples of Queues  Waiting to checkout at a grocery store  The queue for our laser printer  The keyboard remembers the letters you type so even if the computer is busy, they still stay in order when the computer is able to print them.

Queue Code

Demonstration Queue

Stack Stack – A data structure that stores a number of items. The last item entered into a stack is the first item to be removed Push – The act of adding an item to a stack Pop – The act of removing an item from the top of a stack Peek – The act of viewing the value of the item on top of the stack. Note: You cannot see the values for items under the top item. LIFO – Last in First Out – Sometimes used to describe a stack Examples of Stacks  A stack of plates at a cafeteria  A stack of letters

Stack Code

Demonstration Stack

HashTable A collection of values organized by key Hashtables are very good at finding data

Demonstration HashTable

For…Each Statement Some collections allow you to get each item in the collection  Array  ArrayList  SortedList  Others

Demonstration For…Each Statement