Visual C++ Programming: Concepts and Projects Chapter 12B: Linked List (Tutorial)

Slides:



Advertisements
Similar presentations
Chapter 5 introduces the often- used data structure of linked lists. This presentation shows how to implement the most common operations on linked lists.
Advertisements

CSC211 Data Structures Lecture 9 Linked Lists Instructor: Prof. Xiaoyan Li Department of Computer Science Mount Holyoke College.
Linked List 1. Introduction to Linked List 2. Node Class 3. Linked List 4. The Bag Class with Linked List.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 16 – Shopping List Application: Introducing.
Data Structures: A Pseudocode Approach with C
Visual C++ Programming: Concepts and Projects
Chapter 5 Creating an Image Map.
Visual C++ Programming: Concepts and Projects Chapter 13A: Object-Oriented Programming (Concepts)
Chapter 2- Visual Basic Schneider
Tutorial 6 & 7 Symbol Table
C++ Programming: Program Design Including Data Structures, Fifth Edition Chapter 17: Linked Lists.
UML Class Diagram: class Rectangle
Visual C++ Programming: Concepts and Projects
Week 3 - Wednesday.  What did we talk about last time?  Started linked lists.
Data Structures Using C++ 2E
Data Structures Using C++ 2E Chapter 7 Stacks. Data Structures Using C++ 2E2 Objectives Learn about stacks Examine various stack operations Learn how.
Review for Midterm Chapter 1-9 CSc 212 Data Structures.
1 Chapter 3 and 6– Classes, Objects and Methods Object-Oriented Programming Concepts – Read it from Java TutorialJava Tutorial Definition: A class is a.
Programming with Visual C++: Concepts and Projects Chapter 3B: Integral Data (Tutorial)
Programming with Visual C++: Concepts and Projects Chapter 2B: Reading, Processing and Displaying Data (Tutorial)
Linked Lists part 2 CS 244 Brent M. Dingle, Ph.D. Game Design and Development Program Department of Mathematics, Statistics, and Computer Science University.
Classes In C++ 1. What is a class Can make a new type in C++ by declaring a class. A class is an expanded concept of a data structure: instead of holding.
Visual C++ Programming: Concepts and Projects Chapter 11B: Pointers (Tutorial)
Exam 1 Review CS Total Points – 60 Points Writing Programs – 20 Points Tracing Algorithms, determining results, and drawing pictures – 40 Points.
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 19: Stacks and Queues.
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 6B Methods (Tutorial)
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 3B Integral Data (Tutorial)
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 17: Linked Lists (part 2)
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 18: Linked Lists (part 2)
Chapter 13: Overloading and Templates. Objectives In this chapter, you will – Learn about overloading – Become familiar with the restrictions on operator.
Programming with Visual C++: Concepts and Projects Chapter 4B: Selection (Tutorial)
1 Classes II Chapter 7 2 Introduction Continued study of –classes –data abstraction Prepare for operator overloading in next chapter Work with strings.
Chapter 5 Linked List by Before you learn Linked List 3 rd level of Data Structures Intermediate Level of Understanding for C++ Please.
1 Chapter 6 Methods for Making Data Structures. 2 Dynamic Arrays in Data Structures In almost every data structure, we want functions for inserting and.
Chapter 17: Linked Lists. Objectives In this chapter, you will: – Learn about linked lists – Learn the basic properties of linked lists – Explore insertion.
Visual C++ Programming: Concepts and Projects Chapter 10B: Recursion (Tutorial)
1 Project 4: Computing Distance. 222 Computing Distance Write a program to compute the distance between two points. Recall that the distance between the.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 17: Linked Lists.
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 18: Linked Lists.
Linked Lists Data Structures and Algorithms CS 244 Brent M. Dingle, Ph.D. Department of Mathematics, Statistics, and Computer Science University of Wisconsin.
Arrays, Link Lists, and Recursion Chapter 3. Sorting Arrays: Insertion Sort Insertion Sort: Insertion sort is an elementary sorting algorithm that sorts.
An Introduction to Programming Using Alice 2.2, Second Edition Chapter 7 Recursive Algorithms.
Chapter 10 Using Macros, Controls and Visual Basic for Applications (VBA) with Excel Microsoft Excel 2013.
CHAPTER 13B Object Oriented Programming (Tutorial)
Chapter 3 Lists, Stacks, Queues. Abstract Data Types A set of items – Just items, not data types, nothing related to programming code A set of operations.
Link-Based Implementations
Visual C++ Programming: Concepts and Projects
Excel Tutorial 8 Developing an Excel Application
CS 240 Week 2.
Data Structures Using C++ 2E
Pointers and Linked Lists
Chapter 13: Overloading and Templates
Pointers and Linked Lists
Copy Constructor / Destructors Stacks and Queues
CS 215 Final Review Ismail abumuhfouz Fall 2014.
CS Data Structures Chapter 8 Lists Mehmet H Gunes
classes and objects review
UML Class Diagram: class Rectangle
LINKED LISTS CSCD Linked Lists.
Pointers and Linked Lists
Chapter 4 Link Based Implementations
Exam 1 Review CS 3358.
Tutorial 19 - Microwave Oven Application Building Your Own Classes and Objects Outline Test-Driving the Microwave Oven Application Designing.
PC02 Consolidation Loading a witty quote…. PC02 Consolidation Loading a witty quote…
Pointers and Linked Lists
Exam 1 Review CS 3358.
List Implementations Chapter 9.
Chapter 2- Visual Basic Schneider
Data Structures & Algorithms
Linked Lists.
Presentation transcript:

Visual C++ Programming: Concepts and Projects Chapter 12B: Linked List (Tutorial)

Tutorial: Linked List Problem description – This program helps the user visualize a linked list by drawing one on the interface – Buttons are provided to: Create the initial list Add a Node to the front of the list Delete a Node from the front of the list Remove all Nodes (delete the list) 2Programming with Visual C++

Problem Description 3Programming with Visual C++

Problem Description (continued) 4Programming with Visual C++

Problem Description (continued) 5Programming with Visual C++

Problem Description (continued) 6Programming with Visual C++

Problem Description (continued) 7Programming with Visual C++

Problem Description (continued) 8Programming with Visual C++

Problem Description (continued) 9Programming with Visual C++

Problem Description (continued) 10Programming with Visual C++

Problem Description (continued) 11Programming with Visual C++

Design The Node class definition – Start with a UML class diagram – All data members and methods will have public access (+) – Class variable: nodeCount – Instance variables: nodeData, next – Default constructor: Node() 12Programming with Visual C++

Design (continued) 13Programming with Visual C++

Design (continued) Interface sketch – Equal distance between Node rectangles – Arrows drawn to link Nodes – Starting coordinates of the first Node are crucial The positions of all other Nodes are calculated from them 14Programming with Visual C++

Design (continued) 15Programming with Visual C++

Design (continued) The head pointer The head pointer always points to the first Node in the list All insertions and deletions involve the head pointer 16Programming with Visual C++

Design (continued) Table of constants 17Programming with Visual C++

Design (continued) Table of Drawing objects 18Programming with Visual C++

Design (continued) Creating the first Node in a linked list 19Programming with Visual C++

Design (continued) Inserting a new Node – Create the new Node – Point the new Nodes next pointer at the first Node in the list – Assign the head pointer to point to the new Node This always inserts the new Node at the head of the linked list 20Programming with Visual C++

Design (continued) 21Programming with Visual C++

Design (continued) 22Programming with Visual C++

Design (continued) 23Programming with Visual C++

Design (continued) 24Programming with Visual C++

Design (continued) Deleting a Node – Create a temporary Node pointer (temp) – Point temp at the first Node in the linked list – Assign the head pointer to point to the second Node – Delete the Node pointed to by temp This always deletes the Node at the head of the linked list 25Programming with Visual C++

Design (continued) 26Programming with Visual C++

Design (continued) 27Programming with Visual C++

Design (continued) 28Programming with Visual C++

Design (continued) Use a loop to delete each node in the list Delete from the front Reassign head to point to the next Node Delete Nodes until there are no more 29Programming with Visual C++

Design (continued) 30Programming with Visual C++

Development Interface – Only four buttons required Coding – Create Node.h (Node header file) – Create Node.cpp (implementation file) – Finish coding Form1.h (client code) 31Programming with Visual C++

Development (continued) 32Programming with Visual C++

Development (continued) 33Programming with Visual C++

Development (continued) 34Programming with Visual C++

Development (continued) The Node class contains a default constructor – Change this to a prototype – Put the default constructor code in the implementation file (Node.cpp) 35Programming with Visual C++

Development (continued) 36Programming with Visual C++

Development (continued) 37Programming with Visual C++

Development (continued) Enter the code for the Node class in Node.h 38Programming with Visual C++

Development (continued) Write the default constructor code in the implementation file ( Node.cpp ) Remember to include Node.h 39Programming with Visual C++

Development (continued) Client code ( Form1.h ) – Include the Node class definition file ( Node.h ) 40Programming with Visual C++

Development (continued) Client code ( Form1.h ) – Constants, head pointer, and Drawing objects 41Programming with Visual C++

Development (continued) Client code ( Form1.h ) – Code Form1->Load() Instantiate Drawing objects 42Programming with Visual C++

Development (continued) Client code ( Form1.h ) – Code the reset() method Properly enable all buttons Reset class variable Node::nodeCount to 0 43Programming with Visual C++

Coding Write code for btnHead_Click() – Create new head pointer – Draw the linked list – Properly reset the buttons 44Programming with Visual C++

Coding (continued) Write the code for btnInsert_Click() – No more than seven Nodes allowed – Implement three-step insertion algorithm – Draw the linked list 45Programming with Visual C++

Coding (continued) 46Programming with Visual C++

Coding (continued) Code drawNode() – drawNode() is recursive – level is used to determine when to stop drawing Nodes – The location of each Node rectangle is calculated by multiplying nodeDistance and level 47Programming with Visual C++

Coding (continued) 48Programming with Visual C++

Coding (continued) 49Programming with Visual C++

Coding (continued) Draw the current Node If there is another Node linked to it ( next is not the nullptr ), then draw that Node – This is a recursive process – The base case occurs when next is the nullptr 50Programming with Visual C++

Coding (continued) 51Programming with Visual C++

Coding (continued) 52Programming with Visual C++

Testing Check each button – Create a list – Insert nodes (make sure the nodeData is correct) – Try to insert more than seven (not allowed) 53Programming with Visual C++

On Your Own Task 1. Coding btnDelete_Click() Task 2. Coding btnClear_Click() and deleteList() Task 3. Final Testing to make sure all buttons work correctly Programming with Visual C++54

On Your Own (continued) 55Programming with Visual C++