Data Structures and Algorithms. Lab 1. Hands on Data Structures Using C++ Stacks and Queues

Save this PDF as:

Size: px
Start display at page:

Download "Data Structures and Algorithms. Lab 1. Hands on Data Structures Using C++ Stacks and Queues"

Transcription

1 Data Structures and Algorithms Lab 1 Hands on Data Structures Using C++ Stacks and Queues Dr. Rabie A. Ramadan Notes: Students must read this document before the lab and make their code ready for compilation. TA s are not responsible for writing the code to the students. They may help them correcting the errors only. TA s will not accept the code from a student unless it is free of errors, free of warnings, and running. 1. Objective: The objective of this lab is to experiment with the implementation of some of the basic data structures. C++ is our vehicle to implement such structures. Note: Students must have their code written before entering the lab. 2. Introduction: Two of the more common data objects found in computer algorithms are stacks and queues. Both of these objects are special cases of the more general data object, an ordered list. A stack is an ordered list in which all insertions and deletions are made at one end, called the top. A queue is an ordered list in which all insertions take place at one end, the rear, while all deletions take place at the other end, the front. Given a stack S=(a[1],a[2],...a[n]) then we say that a1 is the bottommost element and element a[i] is on top of element a[i-1], 1<i<=n. When viewed as a queue with a[n] as the rear element one says that a[i+1] is behind a[i], 1<i<=n.

2 The restrictions on a stack imply that if the elements A,B,C,D,E are added to the stack, in that order, then the first element to be removed/deleted must be E. Equivalently we say that the last element to be inserted into the stack will be the first to be removed. For this reason stacks are sometimes referred to as Last In First Out (LIFO) lists. The restrictions on queue imply that the first element which is inserted into the queue will be the first one to be removed. Thus A is the first letter to be removed, and queues are known as First In First Out (FIFO) lists. Note that the data object queue as defined here need not necessarily correspond to the mathematical concept of queue in which the insert/delete rules may be different. The stack and queue operations are summarized as follows: A) Adding into stack procedure add(item : items); {add item to the global stack stack; top is the current top of stack and n is its maximum size if top = n then stackfull; top := top+1; stack(top) := item; end: {of add B) Deletion in stack procedure delete(var item : items); {remove top element from the stack stack and put it in the item if top = 0 then stackempty; item := stack(top); top := top-1; end; {of delete

3 These two procedures are so simple that they perhaps need no more explanation. Procedure delete actually combines the functions TOP and DELETE, stackfull and stackempty are procedures which are left unspecified since they will depend upon the particular application. Often a stackfull condition will signal that more storage needs to be allocated and the program re-run. Stackempty is often a meaningful condition. C) Addition into a queue procedure addq (item : items); {add item to the queue q if rear=n then queuefull else rear :=rear+1; q[rear]:=item; end; end;{of addq D) Deletion in a queue procedure deleteq (var item : items); {delete from the front of q and put into item if front = rear then queueempty else front := front+1 item := q[front]; end; end; {of deleteq 3. C++ Implementation: The following C++ code implements the stack and queue operations. However, there might be some errors in the code. One of the students duties is to find these errors and correct them.

4 3.1. Stack Using Arrays // stack.h: header file class Stack { int MaxStack; int EmptyStack; int top; char* items; public: Stack(int); ~Stack(); void push(char); char pop(); int empty(); int full(); ; // stack.cpp: stack functions Stack::Stack(int size) { MaxStack = size; EmptyStack = -1; top = EmptyStack; items = new char[maxstack]; Stack::~Stack() {delete[] items; void Stack::push(char c) { items[++top] = c; char Stack::pop() { return items[top--]; int Stack::full() { return top + 1 == MaxStack; int Stack::empty() { return top == EmptyStack;

5 // stackmain.cpp: use stack #include <iostream.h> int main() { Stack s(10); // 10 chars char ch; while ((ch = cin.get())!= '\n') if (!s.full()) s.push(ch); while (!s.empty()) cout << s.pop(); cout << endl; return 0; 3.2. Stack Using Templates The following program takes the simple stack given elsewhere, and writes it in a "templated" version, that is, in generic form using C++ templates. In the listings below, code related to templates appears in red, while parameters to the template are given in orange. In the implementation, whenever a stack is instantiated, the actual parameters to the template are textually substituted in for the formal parameters to the stack. Thus below, first char and 10 are substituted for Typ and MaxStack. Next double and 4 are substituted for Typ and MaxStack. After this substitution, the compiler compiles the resulting code, which contains only references to specific types, and so can be optimized. The main function below shows the instantiation of two stacks, the first a stack of up to 10 chars, and the second a stack of up to 4 doubles. The code pushes items on each stack until they are full, and then pops them for printing until the stack is empty. As in the earlier programs, this code is simplified, without even any checking for underflow or overflow. This version allocated the actual memory locations for the stack on the program stack, so here there is no memory leak. This version will work for user-defined types also. These C++ features allow the creation of much more complex templated "container" classes in the C++ Standard Template Library (STL).

6 C++ Stack With Template Three separate files: stack.h, stack.cpp, and stacktest.cpp // stack.h: header file class Stack { int EmptyStack; Typ items[maxstack]; int top; public: Stack(); ~Stack(); void push(typ); Typ pop(); int empty(); int full(); ; // stacktest.cpp: use templated stack #include <iostream.h> int main() { Stack<char, 10> s; // 10 chars char ch; while ((ch = cin.get())!= '\n') if (!s.full()) s.push(ch); while (!s.empty()) cout << s.pop(); cout << endl; Stack<double, 4> ds; // 4 doubles double d[] = {1.0, 3.0, 5.0, 7.0, 9.0, 0.0; int i = 0; while (d[i]!= 0.0 &&!ds.full()) if (!ds.full()) ds.push(d[i++]); while (!ds.empty()) cout << ds.pop() << " "; cout << endl; return 0; // stack.cpp: function definitions Stack< Typ, MaxStack >::Stack() { EmptyStack = -1; top = EmptyStack; Stack< Typ, MaxStack >::~Stack() { delete[] items; void Stack< Typ, MaxStack >::push(typ c) { items[ ++top ] = c; Typ Stack< Typ, MaxStack >::pop() { return items[ top-- ]; int Stack< Typ, MaxStack >::full() { return top + 1 == MaxStack; int Stack< Typ, MaxStack >::empty() { return top == EmptyStack;

7 3.3. Queue Using ATL #include <iostream> #include <queue> #include <list> using namespace std; int main() { int thedata[] = {45, 34, 56, 27, 71, 50, 62; queue<int, list<int> > q; cout << "The queue size is now " << q.size() << endl; cout << "Pushing 4 elements " << endl; for (int i = 0; i < 4; ++i) q.push(thedata[i]); cout << "The queue size is now " << q.size() << endl; cout << "Popping 3 elements " << endl; for (int i = 0; i < 3; ++i) { cout << q.front() << endl; q.pop(); cout << "The queue size is now " << q.size() << endl; return 0; 4. Requirements and Deliverable A) Array implementation to the queue B) A time performance comparison between the array and STL implementations for both stack and queue. Explain your answer? 5. References: queuestack/queuepushpopandsize.htm

CHAPTER 4 ESSENTIAL DATA STRUCTRURES

CHAPTER 4 ESSENTIAL DATA STRUCTURES 72 CHAPTER 4 ESSENTIAL DATA STRUCTRURES In every algorithm, there is a need to store data. Ranging from storing a single value in a single variable, to more complex

Stacks. 1 Introduction. 2 The Stack ADT. Prof. Stewart Weiss. CSci 235 Software Design and Analysis II Stacks

1 Introduction are probably the single most important data structure of computer science. They are used across a broad range of applications and have been around for more than fty years, having been invented

CSI33 Data Structures

Outline Department of Mathematics and Computer Science Bronx Community College November 25, 2015 Outline Outline 1 Chapter 12: C++ Templates Outline Chapter 12: C++ Templates 1 Chapter 12: C++ Templates

Object-Oriented Programming, Iouliia Skliarova

Object-Oriented Programming, Iouliia Skliarova Data types define the way you use the storage (memory) in the programs. By specifying a data type, you tell the sompiler how to create a particular piece

Common Data Structures

Data Structures 1 Common Data Structures Arrays (single and multiple dimensional) Linked Lists Stacks Queues Trees Graphs You should already be familiar with arrays, so they will not be discussed. Trees

What is a Stack? Stacks and Queues. Stack Abstract Data Type. Java Interface for Stack ADT. Array-based Implementation

Stacks and Queues What is a Stack? Stores a set of elements in a particular order Accessed in Last-In In-First-Out (LIFO) fashion Real life examples: Pile of books PEZ dispenser Cup trays in cafeteria

15 Pointers and Linked Lists 15.1 Nodes and Linked Lists 828 Nodes 828 Linked Lists 834 Inserting a Node at the Head of a List 835 Pitfall:Losing Nodes 839 Searching a Linked List 840 Pointers as Iterators

Example 7. na20.nada.kth.se 883)./a.out y = y = y = y = #include <iostream.h> #include <math.

In the example above two functions are defined. Both increments the value of i by one, but fcn1 uses call-by-value as parameter passing mechanism and fcn2 uses call-by-reference. call-by-value means that

Cpt S 223. School of EECS, WSU

Abstract Data Types 1 Topics Abstract Data Types (ADTs) Some basic ADTs: Lists Stacks Queues 2 Primitive Data Type vs. Abstract Data Types Primitive DT: ADT: programmer progra ammer Interface (API) e.g.,

1) The postfix expression for the infix expression A+B*(C+D)/F+D*E is ABCD+*F/DE*++

Answer the following 1) The postfix expression for the infix expression A+B*(C+D)/F+D*E is ABCD+*F/DE*++ 2) Which data structure is needed to convert infix notations to postfix notations? Stack 3) The

Application of Stacks: Postfix Expressions Calculator (cont d.)

Application of Stacks: Postfix Expressions Calculator (cont d.) Postfix expression: 6 3 + 2 * = FIGURE 7-15 Evaluating the postfix expression: 6 3 + 2 * = Data Structures Using C++ 2E 1 Application of

Each statement is ended by a semi-colon (;). The formatting is free.

Example 1 cout x; double err, tol=1e-12, x1; int it, maxit=100; it = 0; err = tol + 1; while( err > tol && it < maxit ) x1 = x - (x-cos(x))/(1+sin(x)); err = fabs(

Comp151. Definitions & Declarations

Comp151 Definitions & Declarations Example: Definition /* reverse_printcpp */ #include #include using namespace std; int global_var = 23; // global variable definition void reverse_print(const

csci 210: Data Structures Stacks and Queues

csci 210: Data Structures Stacks and Queues Summary Topics stacks and queues as abstract data types implementations arrays linked lists analysis and comparison application: searching with stacks and queues

Data Structures Using C++ 2E. Chapter 5 Linked Lists

Data Structures Using C++ 2E Chapter 5 Linked Lists Doubly Linked Lists Traversed in either direction Typical operations Initialize the list Destroy the list Determine if list empty Search list for a given

Queue Implementations

Queue Implementations as double 1 2 as double MCS 360 Lecture 17 Introduction to Data Structures Jan Verschelde, 1 October 2010 Queue Implementations as double 1 2 as double a circular as double A can

Data Structures Using C++ 2E. Chapter 7 Stacks

Data Structures Using C++ 2E Chapter 7 Stacks Linked Implementation of Stacks Disadvantage of array (linear) stack representation Fixed number of elements can be pushed onto stack Solution Use pointer

TIE-20106 1 TIE-20106 2

TIE-20106 1 1 List structures In this chapter, a few simple data structures (stack and queue) that can be implemented with arrays and/or lists are covered. Two more complex structures based on lists are

Stacks. Linear data structures

Stacks Linear data structures Collection of components that can be arranged as a straight line Data structure grows or shrinks as we add or remove objects ADTs provide an abstract layer for various operations

Engineering Problem Solving with C++, Etter

Engineering Problem Solving with C++, Etter Chapter 7 Strings 12-11-13 1 Strings Character Strings The string Class. 2 C style strings functions defined in cstring CHARACTER STRINGS 3 C Style Character

Linked Lists, Stacks, Queues, Deques. It s time for a chainge!

Linked Lists, Stacks, Queues, Deques It s time for a chainge! Learning Goals After this unit, you should be able to... Differentiate an abstraction from an implementation. Define and give examples of problems

Module 2 Stacks and Queues: Abstract Data Types

Module 2 Stacks and Queues: Abstract Data Types A stack is one of the most important and useful non-primitive linear data structure in computer science. It is an ordered collection of items into which

Short Notes on Dynamic Memory Allocation, Pointer and Data Structure

Short Notes on Dynamic Memory Allocation, Pointer and Data Structure 1 Dynamic Memory Allocation in C/C++ Motivation /* a[100] vs. *b or *c */ Func(int array_size) double k, a[100], *b, *c; b = (double

Data Structures and Algorithms(3)

Ming Zhang Data Structures and Algorithms Data Structures and Algorithms(3) Instructor: Ming Zhang Textbook Authors: Ming Zhang, Tengjiao Wang and Haiyan Zhao Higher Education Press, 2008.6 (the "Eleventh

Data Structures and Algorithms(3)

Ming Zhang Data Structures and Algorithms Data Structures and Algorithms(3) Instructor: Ming Zhang Textbook Authors: Ming Zhang, Tengjiao Wang and Haiyan Zhao Higher Education Press, 2008.6 (the "Eleventh

Chapter Objectives. Chapter 7. Stacks. Various Types of Stacks LIFO. Empty Stack. Stacks

Chapter Objectives Chapter 7 Stacks Learn about stacks Examine various stack operations Learn how to implement a stack as an array Learn how to implement a stack as a linked list Discover stack applications

St S a t ck a ck nd Qu Q eue 1

Stack and Queue 1 Stack Data structure with Last-In First-Out (LIFO) behavior In Out C B A B C 2 Typical Operations Pop on Stack Push isempty: determines if the stack has no elements isfull: determines

An Incomplete C++ Primer. University of Wyoming MA 5310

An Incomplete C++ Primer University of Wyoming MA 5310 Professor Craig C. Douglas http://www.mgnet.org/~douglas/classes/na-sc/notes/c++primer.pdf C++ is a legacy programming language, as is other languages

Course: Programming II - Abstract Data Types. The ADT Stack. A stack. The ADT Stack and Recursion Slide Number 1

Definition Course: Programming II - Abstract Data Types The ADT Stack The ADT Stack is a linear sequence of an arbitrary number of items, together with access procedures. The access procedures permit insertions

A linear structure is an ordered (e.g., sequenced) arrangement of elements.

Lists, Stacks, and Queues 1 A linear structure is an ordered (e.g., sequenced) arrangement of elements. There are three common types of linear structures: list stack queue random insertion and deletion

Integrating the C++ Standard Template Library Into the Undergraduate Computer Science Curriculum

Integrating the C++ Standard Template Library Into the Undergraduate Computer Science Curriculum James P. Kelsh James.Kelsh@cmich.edu Roger Y. Lee lee@cps.cmich.edu Department of Computer Science Central

Storage Classes CS 110B - Rule Storage Classes Page 18-1 \handouts\storclas

CS 110B - Rule Storage Classes Page 18-1 Attributes are distinctive features of a variable. Data type, int or double for example, is an attribute. Storage class is another attribute. There are four storage

DATA STRUCTURE - STACK

DATA STRUCTURE - STACK http://www.tutorialspoint.com/data_structures_algorithms/stack_algorithm.htm Copyright tutorialspoint.com A stack is an abstract data type ADT, commonly used in most programming

Analysis of a Search Algorithm

CSE 326 Lecture 4: Lists and Stacks 1. Agfgd 2. Dgsdsfd 3. Hdffdsf 4. Sdfgsfdg 5. Tefsdgass We will review: Analysis: Searching a sorted array (from last time) List ADT: Insert, Delete, Find, First, Kth,

QUEUES. Primitive Queue operations. enqueue (q, x): inserts item x at the rear of the queue q

QUEUES A queue is simply a waiting line that grows by adding elements to its end and shrinks by removing elements from the. Compared to stack, it reflects the more commonly used maxim in real-world, namely,

Data Structures and Algorithms C++ Implementation

BK TP.HCM Ho Chi Minh City University of Technology Faculty of Computer Science and Engineering BK TP.HCM Data Structures and Algorithms C++ Implementation Huỳnh Tấn Đạt Email: htdat@cse.hcmut.edu.vn Home

STACK Data Structure:

STACK Data Structure: Data Structures using C Chapter-3 STACK AND QUEUE A stack is an ordered list in which insertions and deletions are made at one end called the top. o If we add the elements A, B, C,

Function Definitions

Functions 8 22 absdiff 14 1. Perspective is messed up here. 2. Picture needs to be redone in truespace. 3. Think of a function as a black box (meaning you shouldn't worry about what is happening inside)

Helpful C++ Transitions A Few Helpful Slides #ifndef Objects using Classes 2 Avoiding Duplicate Headers #ifndef PRODUCT_H #define PRODUCT_H #endif 3 A Node Class Class Node { public: Node (string s); private:

12 Abstract Data Types

12 Abstract Data Types 12.1 Source: Foundations of Computer Science Cengage Learning Objectives After studying this chapter, the student should be able to: Define the concept of an abstract data type (ADT).

Stacks. The push operation adds an item to the top of the stack, hiding any items already on the stack, or initializing the stack if it is empty.

Stacks A stack is a last in, first out (LIFO) abstract data type and data structure. A stack can have any abstract data type as an element, but is characterized by only two fundamental operations: push

Object Oriented Software Design II

Object Oriented Software Design II C++ intro Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa February 26, 2012 G. Lipari (Scuola Superiore Sant Anna) C++ Intro February 26,

Chapter 3: Restricted Structures Page 1

Chapter 3: Restricted Structures Page 1 1 2 3 4 5 6 7 8 9 10 Restricted Structures Chapter 3 Overview Of Restricted Structures The two most commonly used restricted structures are Stack and Queue Both

Object-Oriented Programming. Lecture 8 Dr Piotr Cybula

Object-Oriented Programming Lecture 8 Dr Piotr Cybula Standard Template Library (STL) input/output streams: iostream, fstream, sstream, iomanip string management: string standard

Boolean Expressions, Conditions, Loops, and Enumerations. Precedence Rules (from highest to lowest priority)

Boolean Expressions, Conditions, Loops, and Enumerations Relational Operators == // true if two values are equivalent!= // true if two values are not equivalent < // true if left value is less than the

CpSc212 Goddard Notes Chapter 6. Yet More on Classes. We discuss the problems of comparing, copying, passing, outputting, and destructing

CpSc212 Goddard Notes Chapter 6 Yet More on Classes We discuss the problems of comparing, copying, passing, outputting, and destructing objects. 6.1 Object Storage, Allocation and Destructors Some objects

Comp 245 Data Structures. Stacks

Comp 245 Data Structures Stacks What is a Stack? A LIFO (last in, first out) structure Access (storage or retrieval) may only take place at the TOP NO random access to other elements within the stack An

C++ INTERVIEW QUESTIONS

C++ INTERVIEW QUESTIONS http://www.tutorialspoint.com/cplusplus/cpp_interview_questions.htm Copyright tutorialspoint.com Dear readers, these C++ Interview Questions have been designed specially to get

Simple C++ Programs. Engineering Problem Solving with C++, Etter/Ingber. Dev-C++ Dev-C++ Windows Friendly Exit. The C++ Programming Language

Simple C++ Programs Engineering Problem Solving with C++, Etter/Ingber Chapter 2 Simple C++ Programs Program Structure Constants and Variables C++ Operators Standard Input and Output Basic Functions from

Object Oriented Software Design II

Object Oriented Software Design II Introduction to C++ Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa February 20, 2012 G. Lipari (Scuola Superiore Sant Anna) C++ Intro February

Stacks & Queues. Data structures and Algorithms

Stacks & Queues Data structures and Algorithms Acknowledgement: These slides are adapted from slides provided with Data Structures and Algorithms in C++ Goodrich, Tamassia and Mount (Wiley, 2004) Outline

DATA STRUCTURES USING C

DATA STRUCTURES USING C QUESTION BANK UNIT I 1. Define data. 2. Define Entity. 3. Define information. 4. Define Array. 5. Define data structure. 6. Give any two applications of data structures. 7. Give

PROGRAMMING CONCEPTS AND EMBEDDED PROGRAMMING IN C, C++ and JAVA: Lesson-4: Data Structures: Stacks

PROGRAMMING CONCEPTS AND EMBEDDED PROGRAMMING IN C, C++ and JAVA: Lesson-4: Data Structures: Stacks 1 STACK A structure with a series of data elements with last sent element waiting for a delete operation.

Abstract Data Types. Chapter 2

Chapter 2 Abstract Data Types The second idea at the core of computer science, along with algorithms, is data. In a modern computer, data consists fundamentally of binary bits, but meaningful data is organized

Ch 7-1. Object-Oriented Programming and Classes

2014-1 Ch 7-1. Object-Oriented Programming and Classes May 10, 2014 Advanced Networking Technology Lab. (YU-ANTL) Dept. of Information & Comm. Eng, Graduate School, Yeungnam University, KOREA (Tel : +82-53-810-2497;

Object-Oriented Desin and Prorammin C++ Container Classes Outline Introduction Container Class Objectives Class Library Architecture Parameterized Types Preprocessor Macros enclass void Pointer Method

Adjusted/Modified by Nicole Tobias. Chapter 2: Basic Elements of C++

Adjusted/Modified by Nicole Tobias Chapter 2: Basic Elements of C++ Objectives In this chapter, you will: Become familiar with functions, special symbols, and identifiers in C++ Explore simple data types

C++ Keywords. If/else Selection Structure. Looping Control Structures. Switch Statements. Example Program

C++ Keywords There are many keywords in C++ that are not used in other languages. bool, const_cast, delete, dynamic_cast, const, enum, extern, register, sizeof, typedef, explicit, friend, inline, mutable,

Programming Fundamental. Instructor Name: Lecture-2

Programming Fundamental Instructor Name: Lecture-2 Today s Lecture What is Programming? First C++ Program Programming Errors Variables in C++ Primitive Data Types in C++ Operators in C++ Operators Precedence

Abstract Data Type. EECS 281: Data Structures and Algorithms. The Foundation: Data Structures and Abstract Data Types

EECS 281: Data Structures and Algorithms The Foundation: Data Structures and Abstract Data Types Computer science is the science of abstraction. Abstract Data Type Abstraction of a data structure on that

Linked Lists Linked Lists, Queues, and Stacks CSE 10: Introduction to C Programming Fall 200 Dynamic data structure Size is not fixed at compile time Each element of a linked list: holds a value points

Data Structures and Data Manipulation

Data Structures and Data Manipulation What the Specification Says: Explain how static data structures may be used to implement dynamic data structures; Describe algorithms for the insertion, retrieval

Data Structures. Level 6 C30151. www.fetac.ie. Module Descriptor

The Further Education and Training Awards Council (FETAC) was set up as a statutory body on 11 June 2001 by the Minister for Education and Science. Under the Qualifications (Education & Training) Act,

Data Structures and Algorithms

Data Structures and Algorithms Lecture 4 2016 Stacks and... 1/28 1 2 Circular Linked 3 Queue Syntax and Functions in C++ 4 Stacks and... 2/28 FIFO and LIFO Outline Data structures can be specialized versions

KITES TECHNOLOGY COURSE MODULE (C, C++, DS)

KITES TECHNOLOGY 360 Degree Solution www.kitestechnology.com/academy.php info@kitestechnology.com technologykites@gmail.com Contact: - 8961334776 9433759247 9830639522.NET JAVA WEB DESIGN PHP SQL, PL/SQL

BSc (Hons) Business Information Systems, BSc (Hons) Computer Science with Network Security. & BSc. (Hons.) Software Engineering

BSc (Hons) Business Information Systems, BSc (Hons) Computer Science with Network Security & BSc. (Hons.) Software Engineering Cohort: BIS/05/FT BCNS/05/FT BSE/05/FT Examinations for 2005-2006 / Semester

Language Examples of ADT: C++ Based on C struct type and Simula 67 classes All of the class instances of a class share a single copy of the member functions Each instance of a class has its own copy of

C++ String Variables. 12. C++ Strings. The standard C++ library provides an object string type to complement the string literals used earlier:

C++ String Variables 1 The standard C++ library provides an object string type to complement the string literals used earlier: string Name1, Name2; // must #include A string variable may be assigned

Linear ADTs. Restricted Lists. Stacks, Queues. ES 103: Data Structures and Algorithms 2012 Instructor Dr Atul Gupta

Linear DT-1: Restricted Lists Stacks, Queues tul Gupta Restricted Lists Stack Queue Circular queue Priority queue General Lists rrays Linked list Circular list Doubly linked list Linear DTs 1 Stacks Using

Computer Programming using C

Computer Programming using C Lecture 11: Buffers and linked lists: solutions Dr Julian Miller Room P/M/101 Ext 2383; E-mail: jfm@ohm http://www.elec.york.ac.uk/intsys/users/jfm7 Contents Solution to buffers

Sequential Data Structures

Sequential Data Structures In this lecture we introduce the basic data structures for storing sequences of objects. These data structures are based on arrays and linked lists, which you met in first year

UNIVERSITI MALAYSIA SARAWAK KOTA SAMARAHAN SARAWAK PSD2023 ALGORITHM & DATA STRUCTURE

STUDENT IDENTIFICATION NO UNIVERSITI MALAYSIA SARAWAK 94300 KOTA SAMARAHAN SARAWAK FAKULTI SAINS KOMPUTER & TEKNOLOGI MAKLUMAT (Faculty of Computer Science & Information Technology) Diploma in Multimedia

CSE373: Data Structures and Algorithms Lecture 1: Introduction; ADTs; Stacks/Queues. Linda Shapiro Spring 2016

CSE373: Data Structures and Algorithms Lecture 1: Introduction; ADTs; Stacks/Queues Linda Shapiro Registration We have 180 students registered and others who want to get in. If you re thinking of dropping

Basics of I/O Streams and File I/O

Basics of This is like a cheat sheet for file I/O in C++. It summarizes the steps you must take to do basic I/O to and from files, with only a tiny bit of explanation. It is not a replacement for reading

CS104: Data Structures and Object-Oriented Design (Fall 2013) October 24, 2013: Priority Queues Scribes: CS 104 Teaching Team

CS104: Data Structures and Object-Oriented Design (Fall 2013) October 24, 2013: Priority Queues Scribes: CS 104 Teaching Team Lecture Summary In this lecture, we learned about the ADT Priority Queue. A

DATA STRUCTURE - QUEUE

DATA STRUCTURE - QUEUE http://www.tutorialspoint.com/data_structures_algorithms/dsa_queue.htm Copyright tutorialspoint.com Queue is an abstract data structure, somewhat similar to stack. In contrast to

10CS35: Data Structures Using C

CS35: Data Structures Using C QUESTION BANK REVIEW OF STRUCTURES AND POINTERS, INTRODUCTION TO SPECIAL FEATURES OF C OBJECTIVE: Learn : Usage of structures, unions - a conventional tool for handling a

Data Structures and Algorithms Stacks and Queues

Data Structures and Algorithms Stacks and Queues Chris Brooks Department of Computer Science University of San Francisco Department of Computer Science University of San Francisco p.1/23 6-0: Stacks and

MAX = 5 Current = 0 'This will declare an array with 5 elements. Inserting a Value onto the Stack (Push) -----------------------------------------

=============================================================================================================================== DATA STRUCTURE PSEUDO-CODE EXAMPLES (c) Mubashir N. Mir - www.mubashirnabi.com

1. The memory address of the first element of an array is called A. floor address B. foundation addressc. first address D. base address 2. The memory address of fifth element of an array can be calculated

Introduction to Data Structures and Algorithms

Introduction to Data Structures and Algorithms Chapter: Elementary Data Structures(1) Lehrstuhl Informatik 7 (Prof. Dr.-Ing. Reinhard German) Martensstraße 3, 91058 Erlangen Overview on simple data structures

Appendix M Introduction to Microsoft Visual C++.NET

Appendix M Introduction to Microsoft Visual C++.NET This appendix serves as a quick reference for performing the following operations using the Microsoft Visual C++.NET integrated development environment

List, Stack and Queue. Tom Chao Zhou CSC2100B Data Structures Tutorial 3

List, Stack and Queue Tom Chao Zhou CSC2100B Data Structures Tutorial 3 Outline Structure Linked List Overview Implementation Stack Overview Implementation Queue Overview Implementation Structure A collection

Data Structures and Algorithms

Data Structures and Algorithms CS245-2016S-04 Stacks and Queues David Galles Department of Computer Science University of San Francisco 04-0: Abstract Data Types An Abstract Data Type is a definition of

Last not not Last Last Next! Next! Line Line Forms Forms Here Here Last In, First Out Last In, First Out not Last Next! Call stack: Worst line ever!

ECE 551 C++ Programming, Data structures, and Algorithms Abstract Data Type: Stack Last In First Out (LIFO) 1 2 2 1 4 3 1 3 4 Stacks in Programming Worst line ever! 5 3 1 5 Stacks are not useful for waiting

PES Institute of Technology-BSC QUESTION BANK

PES Institute of Technology-BSC Faculty: Mrs. R.Bharathi CS35: Data Structures Using C QUESTION BANK UNIT I -BASIC CONCEPTS 1. What is an ADT? Briefly explain the categories that classify the functions

Visual Studio 2008 Express Editions

Visual Studio 2008 Express Editions Visual Studio 2008 Installation Instructions Burning a Visual Studio 2008 Express Editions DVD Download (http://www.microsoft.com/express/download/) the Visual Studio

Quiz 4 Solutions EECS 211: FUNDAMENTALS OF COMPUTER PROGRAMMING II. 1 Q u i z 4 S o l u t i o n s

Quiz 4 Solutions Q1: What value does function mystery return when called with a value of 4? int mystery ( int number ) { if ( number

7.7 Case Study: Calculating Depreciation

7.7 Case Study: Calculating Depreciation 1 7.7 Case Study: Calculating Depreciation PROBLEM Depreciation is a decrease in the value over time of some asset due to wear and tear, decay, declining price,

Test Driven Development for Embedded Software

Test Driven Development for Embedded Software James Grenning San Jose, April 2007, ESC Class# 241 Did you write any code this week? Raise your hand. Do you know if your code works? If you are like the

Lecture 4 Notes: Arrays and Strings

6.096 Introduction to C++ January 10, 2011 Massachusetts Institute of Technology John Marrero Lecture 4 Notes: Arrays and Strings 1 Arrays So far we have used variables to store values in memory for later

Engineering Problem Solving with C++, Etter/Ingber

Engineering Problem Solving with C++, Etter/Ingber Chapter 3 Control Structures 1 Control structures Algorithm Development Conditional Expressions Selection Statements Repetition Statements Structuring

Lab 2: Swat ATM (Machine (Machine))

Lab 2: Swat ATM (Machine (Machine)) Due: February 19th at 11:59pm Overview The goal of this lab is to continue your familiarization with the C++ programming with Classes, as well as preview some data structures.

Queues Outline and Required Reading: Queues ( 4.2 except 4.2.4) COSC 2011, Fall 2003, Section A Instructor: N. Vlajic

Queues Outline and Required Reading: Queues ( 4. except 4..4) COSC, Fall 3, Section A Instructor: N. Vlajic Queue ADT Queue linear data structure organized according to first-in/first-out (FIFO) principle!

Appendix M: Introduction to Microsoft Visual C++ 2010 Express Edition

Appendix M: Introduction to Microsoft Visual C++ 2010 Express Edition This book may be ordered from Addison-Wesley in a value pack that includes Microsoft Visual C++ 2010 Express Edition. Visual C++ 2010

WPUNJ Department of Computer Science

1 WPUNJ Department of Computer Science MS Visual C++ 6.0 Student User Manual Table of Contents Page No Introduction ----------------------------------------------------------------------- 2 How to Launch

LC-3 Data Structures. Textbook chapter 10

LC-3 Data Structures Textbook chapter 10 LC-3 data structures Abstract data structures are Defined by the rules for inserting and extracting data In this section, we will talk about The array The stack

Introduction to Data Structures

Introduction to Data Structures Albert Gural October 28, 2011 1 Introduction When trying to convert from an algorithm to the actual code, one important aspect to consider is how to store and manipulate