Linked List. // create a pointer to the head of the linked list // initially the list is empty.

Size: px
Start display at page:

Download "Linked List. // create a pointer to the head of the linked list // initially the list is empty."

Transcription

1 Linked List 1. Linked List A linked list is a series of connected nodes, where each node is a data structure. The nodes are dynamically allocated, used, and then deleted, allowing the linked list to grow or shrink in size as the program runs. 2. The Basic (non-class) Version The linked list header file struct ListNode { int data; ListNode *next; ; The main program #include <iostream> #include "Linked List.h" using namespace std; void main () { ListNode *head; head = NULL; ListNode *ptr; // create a pointer to the head of the linked list // initially the list is empty. // for pointing to a new node // create first new node ptr = new ListNode; // allocate memory for new node ptr >data = 7; // put data in new node ptr >next = NULL; // new node is end of the list // set head to point to this new node // create second new node ptr = new ListNode; // allocate memory for new node ptr >data = 3; // put data in new node ptr >next = head; // link previous node after this node // insert new node at beginning of the list ptr = head; printf("\n"); while(ptr!= NULL){ cout << ptr >data << endl; ptr = ptr >next; system("pause"); Page 1 of 7 Copyright Enoch Hwang 2010

2 Sample output: 3 7 Page 2 of 7 Copyright Enoch Hwang 2010

3 3. Class Version The linked list header file /* * LinkedList.h * an implementation of the linked list * * Created by Enoch Hwang on 2/1/10. * Copyright All rights reserved. * */ #ifndef LINKEDLIST #define LINKEDLIST #include <iostream> using namespace std; class LinkedList{ private: struct ListNode { int data; ListNode *next; ; ListNode *head; public: LinkedList(); void InsertNode(int d); void PrintList(); int DeleteNode(int d); ; #endif Page 3 of 7 Copyright Enoch Hwang 2010

4 The linked list definition file #include "Linked List.h" LinkedList::LinkedList(){ head = NULL; void LinkedList::InsertNode(int d){ ListNode *ptr = new ListNode; ptr >data = d; if(head == NULL){ ptr >next = NULL; else{ ptr >next = head; // allocate memory for new node // put data in new node // if list is empty // set head to point to this new node // otherwise // insert new node at beginning of the list void LinkedList::PrintList(){ ListNode *ptr = head; cout << "" << endl; while(ptr!= NULL){ cout << " " << ptr >data; ptr = ptr >next; cout << endl << endl; int LinkedList::DeleteNode(int d){ ListNode *ptr = head; ListNode *previous; // trailing pointer // need to treat the first node differently if(head >data == d){ // is the first node the one to delete? ptr = head; // yes head = head >next; delete ptr; return 1; else{ // no, then traverse list to find node to delete while((ptr!= NULL) && (ptr >data!= d)){ previous = ptr; // remember the previous node in the list ptr = ptr >next; // next node in list if(ptr){ // if node is found then delete it previous >next = ptr >next; // adjust pointer of previous node delete ptr; // release memory occupied by node return 1; else return 0; Page 4 of 7 Copyright Enoch Hwang 2010

5 The main program /* * This program demonstrates the creation of a linked list * * Created by Enoch Hwang on 2/1/10. * Copyright All rights reserved. */ #include <iostream> #include "Linked List.h" using namespace std; void main (int argc, char * const argv[]) { LinkedList L; // create an empty list cout << "Inserting node 6..." << endl; L.InsertNode(6); cout << "Inserting node 4..." << endl; L.InsertNode(4); cout << "Inserting node 8..." << endl; L.InsertNode(8); cout << "Deleting node 3..." << endl; if(l.deletenode(3)) cout << "Node deleted" << endl; else cout << "Node not deleted" << endl; cout << endl << "Deleting node 4..." << endl; if(l.deletenode(4)) cout << "Node deleted" << endl; else cout << "Node not deleted" << endl; cout << "Deleting node 8..." << endl; L.DeleteNode(8); cout << "Deleting node 6..." << endl; L.DeleteNode(6); system("pause"); Page 5 of 7 Copyright Enoch Hwang 2010

6 Sample output: Inserting node 6... Inserting node 4... Inserting node Deleting node 3... Node not deleted Deleting node 4... Node deleted 8 6 Deleting node Deleting node 6... Page 6 of 7 Copyright Enoch Hwang 2010

7 4. Exercise 1) Try out the non-class version of the linked list program. Make sure you understand the code. 2) Try out the class version of the linked list program. Make sure you understand the code. 3) Modify the class version of the linked list program so that the numbers added into the list are in ascending order when you traverse the list. In other words, when you traverse the linked list from the beginning to the end and print out each data item, the numbers printed out are in ascending order. Hint: you only need to modify the code in the InsertNode routine. 4) Add a sentinel for doing the search. 5) Create a doubly-linked list. 6) Display a menu with the options: 1) add a new node; 2) delete a node; 3) print out the entire linked list; and 0) end. Call the appropriate linked list class function to perform the selected operation. Page 7 of 7 Copyright Enoch Hwang 2010

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

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

More information

Comp151. Definitions & Declarations

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

More information

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 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

More information

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

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

More information

LINKED DATA STRUCTURES

LINKED DATA STRUCTURES LINKED DATA STRUCTURES 1 Linked Lists A linked list is a structure in which objects refer to the same kind of object, and where: the objects, called nodes, are linked in a linear sequence. we keep a reference

More information

Unordered Linked Lists

Unordered Linked Lists Unordered Linked Lists Derive class unorderedlinkedlist from the abstract class linkedlisttype Implement the operations search, insertfirst, insertlast, deletenode See code on page 292 Defines an unordered

More information

Visual Studio 2008 Express Editions

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

More information

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

Data Structures Using C++ 2E. Chapter 5 Linked Lists Data Structures Using C++ 2E Chapter 5 Linked Lists Test #1 Next Thursday During Class Cover through (near?) end of Chapter 5 Objectives Learn about linked lists Become aware of the basic properties of

More information

Pointers and Linked Lists

Pointers and Linked Lists 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

More information

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

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

More information

Queue Implementations

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

More information

Short Notes on Dynamic Memory Allocation, Pointer and Data Structure

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

More information

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

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

More information

Linked Lists Linked Lists, Queues, and Stacks

Linked Lists Linked Lists, Queues, and Stacks 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

More information

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

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

More information

Visual C++ 2010 Tutorial

Visual C++ 2010 Tutorial Visual C++ 2010 Tutorial Fall, 2011 Table of Contents Page No Introduction ------------------------------------------------------------------- 2 Single file program demo --------- -----------------------------------------

More information

Appendix K Introduction to Microsoft Visual C++ 6.0

Appendix K Introduction to Microsoft Visual C++ 6.0 Appendix K Introduction to Microsoft Visual C++ 6.0 This appendix serves as a quick reference for performing the following operations using the Microsoft Visual C++ integrated development environment (IDE):

More information

Lecture 12 Doubly Linked Lists (with Recursion)

Lecture 12 Doubly Linked Lists (with Recursion) Lecture 12 Doubly Linked Lists (with Recursion) In this lecture Introduction to Doubly linked lists What is recursion? Designing a node of a DLL Recursion and Linked Lists o Finding a node in a LL (recursively)

More information

7.7 Case Study: Calculating Depreciation

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,

More information

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

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

More information

Copyright 2001, Bill Trudell. Permission is granted to copy for the PLoP 2001 conference. All other rights reserved.

Copyright 2001, Bill Trudell. Permission is granted to copy for the PLoP 2001 conference. All other rights reserved. The Secret Partner Pattern Revision 3a by Bill Trudell, July 23, 2001 Submitted to the Pattern Languages of Programs Shepherd: Neil Harrison PC Member: Kyle Brown Thumbnail This paper describes the Secret

More information

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

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

More information

An API for Reading the MySQL Binary Log

An API for Reading the MySQL Binary Log An API for Reading the MySQL Binary Log Mats Kindahl Lead Software Engineer, MySQL Replication & Utilities Lars Thalmann Development Director, MySQL Replication, Backup & Connectors

More information

Linked List as an ADT (cont d.)

Linked List as an ADT (cont d.) Linked List as an ADT (cont d.) Default constructor Initializes list to an empty state Destroy the list Deallocates memory occupied by each node Initialize the list Reinitializes list to an empty state

More information

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 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

More information

Illustration 1: Diagram of program function and data flow

Illustration 1: Diagram of program function and data flow The contract called for creation of a random access database of plumbing shops within the near perimeter of FIU Engineering school. The database features a rating number from 1-10 to offer a guideline

More information

Networks and Protocols Course: 320301 International University Bremen Date: 2004-11-24 Dr. Jürgen Schönwälder Deadline: 2004-12-03.

Networks and Protocols Course: 320301 International University Bremen Date: 2004-11-24 Dr. Jürgen Schönwälder Deadline: 2004-12-03. Networks and Protocols Course: 320301 International University Bremen Date: 2004-11-24 Dr. Jürgen Schönwälder Deadline: 2004-12-03 Problem Sheet #10 Problem 10.1: finger rpc server and client implementation

More information

Cpt S 223. School of EECS, WSU

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.,

More information

Basics of I/O Streams and File I/O

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

More information

Creating a Simple Visual C++ Program

Creating a Simple Visual C++ Program CPS 150 Lab 1 Name Logging in: Creating a Simple Visual C++ Program 1. Once you have signed for a CPS computer account, use the login ID and the password password (lower case) to log in to the system.

More information

IVI Configuration Store

IVI Configuration Store Agilent Developer Network White Paper Stephen J. Greer Agilent Technologies, Inc. The holds information about IVI drivers installed on the computer and configuration information for an instrument system.

More information

SQLITE C/C++ TUTORIAL

SQLITE C/C++ TUTORIAL http://www.tutorialspoint.com/sqlite/sqlite_c_cpp.htm SQLITE C/C++ TUTORIAL Copyright tutorialspoint.com Installation Before we start using SQLite in our C/C++ programs, we need to make sure that we have

More information

10CS35: Data Structures Using C

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

More information

Member Functions of the istream Class

Member Functions of the istream Class Member Functions of the istream Class The extraction operator is of limited use because it always uses whitespace to delimit its reads of the input stream. It cannot be used to read those whitespace characters,

More information

EP241 Computer Programming

EP241 Computer Programming EP241 Computer Programming Topic 10 Basic Classes Department of Engineering Physics University of Gaziantep Course web page www.gantep.edu.tr/~bingul/ep241 Sep 2013 Sayfa 1 Introduction In this lecture

More information

The University of Alabama in Huntsville Electrical and Computer Engineering CPE 112 01 Test #4 November 20, 2002. True or False (2 points each)

The University of Alabama in Huntsville Electrical and Computer Engineering CPE 112 01 Test #4 November 20, 2002. True or False (2 points each) True or False (2 points each) The University of Alabama in Huntsville Electrical and Computer Engineering CPE 112 01 Test #4 November 20, 2002 1. Using global variables is better style than using local

More information

DATA STRUCTURES USING C

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

More information

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

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

More information

Algorithms and Data Structures Written Exam Proposed SOLUTION

Algorithms and Data Structures Written Exam Proposed SOLUTION Algorithms and Data Structures Written Exam Proposed SOLUTION 2005-01-07 from 09:00 to 13:00 Allowed tools: A standard calculator. Grading criteria: You can get at most 30 points. For an E, 15 points are

More information

CSI33 Data Structures

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

More information

Lecture 11 Doubly Linked Lists & Array of Linked Lists. Doubly Linked Lists

Lecture 11 Doubly Linked Lists & Array of Linked Lists. Doubly Linked Lists Lecture 11 Doubly Linked Lists & Array of Linked Lists In this lecture Doubly linked lists Array of Linked Lists Creating an Array of Linked Lists Representing a Sparse Matrix Defining a Node for a Sparse

More information

Lecture 11 Array of Linked Lists

Lecture 11 Array of Linked Lists Lecture 11 Array of Linked Lists In this lecture Array of Linked Lists Creating an Array of Linked Lists Representing a Sparse Matrix Defining a Node for Sparse Matrix Exercises Solutions An Array of Linked

More information

CHAPTER 4 ESSENTIAL DATA STRUCTRURES

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

More information

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

More information

Help on the Embedded Software Block

Help on the Embedded Software Block Help on the Embedded Software Block Powersim Inc. 1. Introduction The Embedded Software Block is a block that allows users to model embedded devices such as microcontrollers, DSP, or other devices. It

More information

Developing an ODBC C++ Client with MySQL Database

Developing an ODBC C++ Client with MySQL Database Developing an ODBC C++ Client with MySQL Database Author: Rajinder Yadav Date: Aug 21, 2007 Web: http://devmentor.org Email: rajinder@devmentor.org Assumptions I am going to assume you already know how

More information

Common Data Structures

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

More information

Object Oriented Software Design II

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

More information

Data Structures using OOP C++ Lecture 1

Data Structures using OOP C++ Lecture 1 References: 1. E Balagurusamy, Object Oriented Programming with C++, 4 th edition, McGraw-Hill 2008. 2. Robert Lafore, Object-Oriented Programming in C++, 4 th edition, 2002, SAMS publishing. 3. Robert

More information

Node-Based Structures Linked Lists: Implementation

Node-Based Structures Linked Lists: Implementation Linked Lists: Implementation CS 311 Data Structures and Algorithms Lecture Slides Monday, March 30, 2009 Glenn G. Chappell Department of Computer Science University of Alaska Fairbanks CHAPPELLG@member.ams.org

More information

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. 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

More information

Passing 1D arrays to functions.

Passing 1D arrays to functions. Passing 1D arrays to functions. In C++ arrays can only be reference parameters. It is not possible to pass an array by value. Therefore, the ampersand (&) is omitted. What is actually passed to the function,

More information

Brent A. Perdue. July 15, 2009

Brent A. Perdue. July 15, 2009 Title Page Object-Oriented Programming, Writing Classes, and Creating Libraries and Applications Brent A. Perdue ROOT @ TUNL July 15, 2009 B. A. Perdue (TUNL) OOP, Classes, Libraries, Applications July

More information

C++ INTERVIEW QUESTIONS

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

More information

Project 4 DB A Simple database program

Project 4 DB A Simple database program Project 4 DB A Simple database program Due Date April (Friday) Before Starting the Project Read this entire project description before starting Learning Objectives After completing this project you should

More information

/* File: blkcopy.c. size_t n

/* File: blkcopy.c. size_t n 13.1. BLOCK INPUT/OUTPUT 505 /* File: blkcopy.c The program uses block I/O to copy a file. */ #include main() { signed char buf[100] const void *ptr = (void *) buf FILE *input, *output size_t

More information

A binary search tree or BST is a binary tree that is either empty or in which the data element of each node has a key, and:

A binary search tree or BST is a binary tree that is either empty or in which the data element of each node has a key, and: Binary Search Trees 1 The general binary tree shown in the previous chapter is not terribly useful in practice. The chief use of binary trees is for providing rapid access to data (indexing, if you will)

More information

Ordered Lists and Binary Trees

Ordered Lists and Binary Trees Data Structures and Algorithms Ordered Lists and Binary Trees Chris Brooks Department of Computer Science University of San Francisco Department of Computer Science University of San Francisco p.1/62 6-0:

More information

Data Structures and Algorithms C++ Implementation

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

More information

CSE 211: Data Structures Lecture Notes VII

CSE 211: Data Structures Lecture Notes VII CSE 211: Data Structures Lecture Notes VII LINKED LISTS In the previous lectures we have seen the representation of ordered lists using an array and sequential mapping. These representations had the property

More information

Ch 7-1. Object-Oriented Programming and Classes

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;

More information

Sample Questions Csci 1112 A. Bellaachia

Sample Questions Csci 1112 A. Bellaachia Sample Questions Csci 1112 A. Bellaachia Important Series : o S( N) 1 2 N N i N(1 N) / 2 i 1 o Sum of squares: N 2 N( N 1)(2N 1) N i for large N i 1 6 o Sum of exponents: N k 1 k N i for large N and k

More information

Lab 2: Swat ATM (Machine (Machine))

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.

More information

Parallel Programming with MPI on the Odyssey Cluster

Parallel Programming with MPI on the Odyssey Cluster Parallel Programming with MPI on the Odyssey Cluster Plamen Krastev Office: Oxford 38, Room 204 Email: plamenkrastev@fas.harvard.edu FAS Research Computing Harvard University Objectives: To introduce you

More information

Data Structures, Practice Homework 2, with Solutions (not to be handed in)

Data Structures, Practice Homework 2, with Solutions (not to be handed in) Data Structures, Practice Homework 2, with Solutions (not to be handed in) 1. Carrano, 4th edition, Chapter 7, Exercise 4. Consider a function int Queue::getNumberOfElements() const that returns the number

More information

Circular Linked List. Algorithms and Data Structures

Circular Linked List. Algorithms and Data Structures Circular Linked List EENG212 Algorithms and Data Structures Circular Linked Lists In linear linked lists if a list is traversed (all the elements visited) an external pointer to the listmust be preserved

More information

Lecture Notes on Binary Search Trees

Lecture Notes on Binary Search Trees Lecture Notes on Binary Search Trees 15-122: Principles of Imperative Computation Frank Pfenning Lecture 17 March 17, 2010 1 Introduction In the previous two lectures we have seen how to exploit the structure

More information

Stacks. Linear data structures

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

More information

1 Abstract Data Types Information Hiding

1 Abstract Data Types Information Hiding 1 1 Abstract Data Types Information Hiding 1.1 Data Types Data types are an integral part of every programming language. ANSI-C has int, double and char to name just a few. Programmers are rarely content

More information

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

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

More information

Note: Syntactically, a ; is needed at the end of a struct definition.

Note: Syntactically, a ; is needed at the end of a struct definition. Structs, Classes, and Arrays Structs A type representation containing a set of heterogeneous members with possibly varying types. struct Student { string name; int id; double tuition; ; Note: Syntactically,

More information

- Easy to insert & delete in O(1) time - Don t need to estimate total memory needed. - Hard to search in less than O(n) time

- Easy to insert & delete in O(1) time - Don t need to estimate total memory needed. - Hard to search in less than O(n) time Skip Lists CMSC 420 Linked Lists Benefits & Drawbacks Benefits: - Easy to insert & delete in O(1) time - Don t need to estimate total memory needed Drawbacks: - Hard to search in less than O(n) time (binary

More information

CS 103 Lab Linux and Virtual Machines

CS 103 Lab Linux and Virtual Machines 1 Introduction In this lab you will login to your Linux VM and write your first C/C++ program, compile it, and then execute it. 2 What you will learn In this lab you will learn the basic commands and navigation

More information

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 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

More information

Sequential Program Execution

Sequential Program Execution Sequential Program Execution Quick Start Compile step once always g++ -o Realtor1 Realtor1.cpp mkdir labs cd labs Execute step mkdir 1 Realtor1 cd 1 cp../0/realtor.cpp Realtor1.cpp Submit step cp /samples/csc/155/labs/1/*.

More information

C++ Programming: From Problem Analysis to Program Design, Fifth Edition. Chapter 3: Input/Output

C++ Programming: From Problem Analysis to Program Design, Fifth Edition. Chapter 3: Input/Output C++ Programming: From Problem Analysis to Program Design, Fifth Edition Chapter 3: Input/Output Objectives In this chapter, you will: Learn what a stream is and examine input and output streams Explore

More information

5 CLASSES CHAPTER. 5.1 Object-Oriented and Procedural Programming. 5.2 Classes and Objects 5.3 Sample Application: A Clock Class

5 CLASSES CHAPTER. 5.1 Object-Oriented and Procedural Programming. 5.2 Classes and Objects 5.3 Sample Application: A Clock Class CHAPTER 5 CLASSES class head class struct identifier base spec union class name 5.1 Object-Oriented and Procedural Programming 5.2 Classes and Objects 5.3 Sample Application: A Clock Class 5.4 Sample Application:

More information

C++ Input/Output: Streams

C++ Input/Output: Streams C++ Input/Output: Streams 1 The basic data type for I/O in C++ is the stream. C++ incorporates a complex hierarchy of stream types. The most basic stream types are the standard input/output streams: istream

More information

Surface and Volumetric Data Rendering and Visualisation

Surface and Volumetric Data Rendering and Visualisation Surface and Volumetric Data Rendering and Visualisation THE Qt TOOLKIT Department of Information Engineering Faculty of Engineering University of Brescia Via Branze, 38 25231 Brescia - ITALY 1 What is

More information

Project 3: Image Enhancement - Spatial vs. Frequency Domain Filters. Steven Young: ECE 572

Project 3: Image Enhancement - Spatial vs. Frequency Domain Filters. Steven Young: ECE 572 Project 3: Image Enhancement - Spatial vs. Frequency Domain Filters Steven Young: ECE 572 Due: October 3, 20 Abstract The purpose of this project is to explore some simple image enhancement algorithms.

More information

Lecture Notes on Binary Search Trees

Lecture Notes on Binary Search Trees Lecture Notes on Binary Search Trees 15-122: Principles of Imperative Computation Frank Pfenning André Platzer Lecture 17 October 23, 2014 1 Introduction In this lecture, we will continue considering associative

More information

Data Structures Using C++

Data Structures Using C++ Data Structures Using C++ 1.1 Introduction Data structure is an implementation of an abstract data type having its own set of data elements along with functions to perform operations on that data. Arrays

More information

Data Structures and Algorithms Lists

Data Structures and Algorithms Lists Data Structures and Algorithms Lists Chris Brooks Department of Computer Science University of San Francisco Department of Computer Science University of San Francisco p.1/19 5-0: Abstract Data Types An

More information

Output: 12 18 30 72 90 87. struct treenode{ int data; struct treenode *left, *right; } struct treenode *tree_ptr;

Output: 12 18 30 72 90 87. struct treenode{ int data; struct treenode *left, *right; } struct treenode *tree_ptr; 50 20 70 10 30 69 90 14 35 68 85 98 16 22 60 34 (c) Execute the algorithm shown below using the tree shown above. Show the exact output produced by the algorithm. Assume that the initial call is: prob3(root)

More information

Name: Class: Date: 9. The compiler ignores all comments they are there strictly for the convenience of anyone reading the program.

Name: Class: Date: 9. The compiler ignores all comments they are there strictly for the convenience of anyone reading the program. Name: Class: Date: Exam #1 - Prep True/False Indicate whether the statement is true or false. 1. Programming is the process of writing a computer program in a language that the computer can respond to

More information

Introduction to Object-Oriented Programming

Introduction to Object-Oriented Programming Introduction to Object-Oriented Programming Linked Lists Christopher Simpkins chris.simpkins@gatech.edu CS 1331 (Georgia Tech) Linked Lists 1 / 12 Linked Lists Dynamic data structures Singly linked lists

More information

Fondamenti di C++ - Cay Horstmann 1

Fondamenti di C++ - Cay Horstmann 1 Fondamenti di C++ - Cay Horstmann 1 Review Exercises R10.1 Line 2: Can't assign int to int* Line 4: Can't assign Employee* to Employee Line 6: Can't apply -> to object Line 7: Can't delete object Line

More information

DATA STRUCTURE - STACK

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

More information

Software Development to Control the Scorbot ER VII Robot With a PC

Software Development to Control the Scorbot ER VII Robot With a PC Software Development to Control the Scorbot ER VII Robot With a PC ANTÓNIO FERROLHO Electrical Engineering Department Superior School of Technology of the Polytechnic Institute of Viseu Campus Politécnico

More information

Coding Rules. Encoding the type of a function into the name (so-called Hungarian notation) is forbidden - it only confuses the programmer.

Coding Rules. Encoding the type of a function into the name (so-called Hungarian notation) is forbidden - it only confuses the programmer. Coding Rules Section A: Linux kernel style based coding for C programs Coding style for C is based on Linux Kernel coding style. The following excerpts in this section are mostly taken as is from articles

More information

Drawing Text with SDL

Drawing Text with SDL Drawing Text with SDL Note: This tutorial assumes that you already know how to display a window and draw a sprite with SDL. Setting Up the SDL TrueType Font Library To display text with SDL, you need the

More information

Questions 1 through 25 are worth 2 points each. Choose one best answer for each.

Questions 1 through 25 are worth 2 points each. Choose one best answer for each. Questions 1 through 25 are worth 2 points each. Choose one best answer for each. 1. For the singly linked list implementation of the queue, where are the enqueues and dequeues performed? c a. Enqueue in

More information

Analysis of a Search Algorithm

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,

More information

Coding conventions and C++-style

Coding conventions and C++-style Chapter 1 Coding conventions and C++-style This document provides an overview of the general coding conventions that are used throughout oomph-lib. Knowledge of these conventions will greatly facilitate

More information

Specific Simple Network Management Tools

Specific Simple Network Management Tools Specific Simple Network Management Tools Jürgen Schönwälder University of Osnabrück Albrechtstr. 28 49069 Osnabrück, Germany Tel.: +49 541 969 2483 Email: Web:

More information

Data Structures and Algorithms

Data Structures and Algorithms Data Structures and Algorithms CS245-2016S-05 Abstract Data Types and Lists David Galles Department of Computer Science University of San Francisco 05-0: Abstract Data Types Recall that an Abstract Data

More information

PES Institute of Technology-BSC QUESTION BANK

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

More information

CORBA Programming with TAOX11. The C++11 CORBA Implementation

CORBA Programming with TAOX11. The C++11 CORBA Implementation CORBA Programming with TAOX11 The C++11 CORBA Implementation TAOX11: the CORBA Implementation by Remedy IT TAOX11 simplifies development of CORBA based applications IDL to C++11 language mapping is easy

More information