1. The user will be able to Search 1,000,000 Records by Part.No and display the sought record in no more than.5 seconds. The user will be able to.

Slides:



Advertisements
Similar presentations
Linked Lists Geletaw S..
Advertisements

Stacks, Queues, and Linked Lists
EENG212 Algorithms and Data Structures
Chapter 3 – Lists A list is just what the name implies, a finite, ordered sequence of items. Order indicates each item has a position. A list of size 0.
CSE Lecture 12 – Linked Lists …
Data Structure Lecture-3 Prepared by: Shipra Shukla Assistant Professor Kaziranga University.
Queues A waiting line that grows by adding elements to its end and shrinks by taking elements from its front Line at the grocery store Cars in traffic.
Module R2 Overview. Process queues As processes enter the system and transition from state to state, they are stored queues. There may be many different.
Review of Stacks and Queues Dr. Yingwu Zhu. Our Focus Only link-list based implementation of Stack class Won’t talk about different implementations of.
Advanced Data Structures Stack –a stack is dynamic data items in a linear order, such that the item first "pushed" in is the last item "popped" out. Think.
Stacks, Queues, and Deques. 2 A stack is a last in, first out (LIFO) data structure Items are removed from a stack in the reverse order from the way they.
Data Structure (Part I) Stacks and Queues. Introduction to Stack An stack is a ordered list in which insertion and deletions are made at one end. –The.
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.
Chapter 6: Stacks STACK APPLICATIONS STACK IMPLEMENTATIONS CS
Data Structures: A Pseudocode Approach with C
Chapter 13 Pointers and Linked Lists. Nodes and Linked Lists Linked list: A sequence of nodes in which each node is linked or connected to the node preceding.
CS 106 Introduction to Computer Science I 12 / 06 / 2006 Instructor: Michael Eckmann.
Chapter 4 ADT Sorted List.
1 Data Structures Data Structures Topic #2. 2 Today’s Agenda Data Abstraction –Given what we talked about last time, we need to step through an example.
1 Stack Data : a collection of homogeneous elements arranged in a sequence. Only the first element may be accessed Main Operations: Push : insert an element.
Object Oriented Data Structures
Chapter 12 Data Structure Associate Prof. Yuh-Shyan Chen Dept. of Computer Science and Information Engineering National Chung-Cheng University.
1 C++ Classes and Data Structures Jeffrey S. Childs Chapter 8 Stacks and Queues Jeffrey S. Childs Clarion University of PA © 2008, Prentice Hall.
2 Preliminaries Options for implementing an ADT List Array has a fixed size Data must be shifted during insertions and deletions Linked list is able to.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 122 – Data Structures Custom Templatized Data Structures.
Linked Lists list elements are stored, in memory, in an arbitrary order explicit information (called a link) is used to go from one element to the next.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley. Ver Chapter 4: Linked Lists Data Abstraction & Problem Solving with.
Copyright © 2008 Pearson Addison-Wesley. All rights reserved. Chapter 13 Pointers and Linked Lists.
C++ Classes and Data Structures Jeffrey S. Childs
DATA STRUCTURES AND ALGORITHMS Lecture Notes 4 Prepared by İnanç TAHRALI.
COP3530 Data Structures600 Stack Stack is one the most useful ADTs. Like list, it is a collection of data items. Supports “LIFO” (Last In First Out) discipline.
Copyright © 2012 Pearson Education, Inc. Chapter 18: Stacks And Queues.
Stacks. A stack is a data structure that holds a sequence of elements and stores and retrieves items in a last-in first- out manner (LIFO). This means.
1 Chapter 7 Stacks and Queues. 2 Stack ADT Recall that ADT is abstract data type, a set of data and a set of operations that act upon the data. In a stack,
Chapter 1 Object Oriented Programming. OOP revolves around the concept of an objects. Objects are created using the class definition. Programming techniques.
A first look an ADTs Solving a problem involves processing data, and an important part of the solution is the careful organization of the data In order.
1 Chapter 7 The Linked List as a Data Structure. 2 The List ADT A list is a list of elements. The list of elements consist of the data acted upon by list.
1 Chapter 16 Linked Structures Dale/Weems. 2 Chapter 16 Topics l Meaning of a Linked List l Meaning of a Dynamic Linked List l Traversal, Insertion and.
Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Stacks.
1 Linked-list, stack and queue. 2 Outline Abstract Data Type (ADT)‏ Linked list Stack Queue.
Review of Stacks and Queues Dr. Yingwu Zhu. How does a Stack Work? Last-in-First-out (LIFO) data structure Adding an item Push operation Removing an item.
1 Working with Pointers An exercise in destroying your computer.
APS105 Lists. Structures Arrays allow a collection of elements –All of the same type How to collect elements of different types? –Structures; in C: struct.
Generic lists Vassilis Athitsos. Problems With Textbook Interface? Suppose that we fix the first problem, and we can have multiple stacks. Can we have.
Chapter 6 Lists Plus. What is a Class Template? A class template allows the compiler to generate multiple versions of a class type by using type parameters.
Data Structures. Abstract Data Type A collection of related data is known as an abstract data type (ADT) Data Structure = ADT + Collection of functions.
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.
2005MEE Software Engineering Lecture 7 –Stacks, Queues.
There Will Be Times That You Come To Class & I Dump A Whole Bunch Of New Stuff On You & You Leave Confused! TODAY MAY BE ONE OF THOSE DAYS! You.
Linked List.  Is a series of connected nodes, where each node is a data structure with data and pointer(s) Advantages over array implementation  Can.
1 Data Structures and Algorithms Stack. 2 The Stack ADT Introduction to the Stack data structure Designing a Stack class using dynamic arrays Linked Stacks.
UNIT-II Topics to be covered Singly linked list Circular linked list
Lecture No.05 Data Structures Dr. Sohail Aslam.  Josephus Problem #include "CList.cpp" void main(int argc, char *argv[]) { CList list; int i, N=10, M=3;
1 Data Structures and Algorithms Stack. 2 The Stack ADT Introduction to the Stack data structure Designing a Stack class using dynamic arrays Linked Stacks.
18 Chapter Stacks and Queues
CS505 Data Structures and Algorithms
Pointers and Linked Lists
Chapter 4 The easy stuff.
Pointers and Linked Lists
Data Structure Interview Question and Answers
CSE 143 Linked Lists [Chapter , 8.8] 3/30/98.
Stacks and Queues.
CMSC 341 Lecture 5 Stacks, Queues
Chapter 16-2 Linked Structures
Stacks, Queues, and Deques
Linked List (Part I) Data structure.
18.5 Linked Queues Like a stack, a queue can be implemented using pointers and nodes Allows dynamic sizing, avoids issue of wrapping indices NULL front.
Chapter 16 Linked Structures
Stacks, Queues, and Deques
Presentation transcript:

1

The user will be able to Search 1,000,000 Records by Part.No and display the sought record in no more than.5 seconds. The user will be able to Add a New Part to 999,999 others in no more that 1.0 seconds. The program will produce a Quick & Efficient Listing of all of the items in any one department by PartName; this is to be accomplished about as fast as the printer can print the report. Most Systems Should Have Some Written Requirements

There Are 4 Types Of Linked Lists (Should Not Be A New Concept To You!)

Single Linked List - 1 Node Info Right Ptr Three Ways We Normally Implement This ADT 1] Dynamic Memory Node (Hopefully You Have Done) 2] Dynamic Memory Array Of These Nodes 3] Direct Access File Of These Nodes SLNode

Single Linked List - 2 We Pointers To Reference Each List We Will Have A Direct Access File Of These Nodes Front Rear Header Node We Will Have A Direct Access File Of These Header Nodes Implement The Direct Access File Solution With 2 Files!

Circular Linked List Rear HeaderNode Implement The Direct Access File Solution With 2 Files! SLNode

Doubly Linked List Header Node Implement The Direct Access File Solution With 2 Files! DLNode Front Rear

Double Circular Linked List Rear Header Node Implement The Direct Access File Solution With 2 Files! DLNode

We Are Going To Implement 1] Internal Memory Array Solution 2] Direct Access File Solution Doubly Linked List

This Is Not Going To Be A Course Where You Type In What I Type! I Am Going To Help You Code An Internal Memory Solution! You Are Going To Translate These Ideas To The Direct Access File Solution!

Double Linked Lists - Meet The Specification ?

Sometimes Divide & Conquer Is Not Enough We Shall Use Apply The Algorithmic Logic For A Specific Application To See If It Works For Us!

23

Extract The File Into C:\Temp Name The Folder TomH-DLList  (Use Your Name) 24

typedef long int NodePtr;

Need 3 Classes

The DLNode Class Is Quite Simple. In Order To Move Along Faster, I Have Created The Class For You To Use.

DLNode (Templated!) template class DLNode { public: DLNode(void); DLNode(InfoType NewInfo); ~DLNode(void); void Display(char Message [] = "", bool PrintTitles = false, bool PrintTopLine = true, bool PrintBottomLine = true, NodePtr RecordNo = NILL); void Display(long int RecordNo); //private: NodePtr Left, Right; bool Deleted; InfoType Info; };

DLNode

Base Header Class

ListHeader class ListHeader { public: ListHeader(void); ~ListHeader(void); void Update(Integer NewInt, char Direction); void Display (char Message []="", bool DisplayTitles = true, bool DisplayTopLine = true, bool DisplayBottomLine = true, long int Subscript = -9999); // private: NodePtr Front, Rear; };

ListHeader

Inheritance – PartListHeader Inherits ListHeader class PartListHeader : public ListHeader { public: PartListHeader(char NewName[] = "", char NewManager[] = ""); void Set (char NewName[] = "", char NewManager[] = ""); ~PartListHeader(void); void Update(Part NewPart, char Direction); void Display (char Message []="", bool DisplayTitles = true, bool DisplayTopLine = true, bool DisplayBottomLine = true, long int Subscript = -9999); friend ostream & operator << (ostream & OutputStream, PartListHeader S); // private: char Name[40], Manager[35]; long int NoParts; double TotalInvestment; };

PartListHeader

Snapshot Of Inventory System Header File

Sketch List No-1. No-2, No-3

Sketch List No F R #

Sketch List No-2 F R #

Sketch List No-3 F R # 0 3 EMPTY!

DA_DLList Sears(“Sears.hf”, “Sears.nf”,4,7); You should be able to trace the Nodes In Header[1], Header[2], etc.

Data Members DLNode * Nodes; unsigned long int MaxNodes; NodePtr Avail; HeaderType * Headers; unsigned long int MaxHeaders;

DLList Sears (4, 5); void CreateNodes(int MaxNodes); DLNode * Nodes; unsigned long int MaxNodes; NodePtr Avail; void CreateHeaderNodes(int MaxHeaders); HeaderType * Headers; unsigned long int MaxHeaders;

HeaderType * Headers; DLNode * Nodes; NodePtr Avail; unsigned long int MaxNodes, MaxHeaders; Headers // // // // F R L InfoDR / T T T T T T T T Nodes DLList Sears(4, 8);

DLNode * Nodes; NodePtr Avail; Nodes[0].Right  Store Avail Prepare To Write To File Later, we might choose to write the Nodes & Headers to files to store data between program executions. This provides a storage location for Aval L InfoDR / T T T T T T T T Nodes

DLNode * Nodes; unsigned long int MaxNodes; NodePtr Avail;

DLNode * Nodes; NodePtr Avail; unsigned long int MaxNodes, L InfoDR Nodes DLList Sears(4, 8);  Constructor  CreateNodes();

L InfoDR Nodes DLNode * Nodes; NodePtr Avail; unsigned long int MaxNodes, DLList Sears(4, 8);  Constructor  CreateNodes(); L InfoDR / T T T T T T T T Nodes

DLNode * Nodes; NodePtr Avail; unsigned long int MaxNodes, DLList Sears(4, 8);  Constructor  CreateNodes(); L InfoDR / T T T T T T T T Nodes ? 8

DLNode * Nodes; NodePtr Avail; unsigned long int MaxNodes, DLList Sears(4, 8);  Constructor  CreateNodes(); L InfoDR / T T T T T T T T Nodes 8 ? 1

Code CreateNodes For Internal Memory

HeaderType * Headers; unsigned long int MaxHeaders;

HeaderType * Headers; unsigned long int MaxHeaders; DLList Sears(4, 8);  Constructor  CreateHeaders(); Headers // // // // F R

HeaderType * Headers; unsigned long int MaxHeaders; DLList Sears(4, 8);  Constructor  CreateHeaders(); Headers // // // // F R 1 4

Code CreateHeaders For Internal Memory

DLList Sears (4, 5); void CreateNodes(int MaxNodes); void CreateHeaderNodes(int MaxHeaders); Code Constructor For Internal Memory

We Will Use TWO CONSTRUCTORS This First Constructor Is Run The First Time A DA_DLList Is Created!

We Will Use TWO CONSTRUCTORS This Second Constructor Is Run After The DA_DLList Has Been Created. IT IS RUN MANY MANY TIMES!

Empty DA_DLList I Want To Show You Some Empty Lists With Direct Access File Implementation

Empty Trinity DA_DLList Trinity ("Trinity.hf", "Trinity.nf", 6, 3); InitializeStudentListHeaderFile(Trinity.hfp);

Empty Num DA_DLList Num ("Num.hf", "Num.nf", 3, 7);

Empty NorthPark DA_DLList NorthPark ("NorthPark.hf", "NorthPark.nf", 3, 7); InitializeAutoHeaderFile(NorthPark.hfp);

Empty Inventory DA_DLList Inventory ("Inventory.hf", "Inventory.nf", 4, 7); InitializePartListHeaderFile(Inventory.hfp);

Empty SmithBarney DA_DLList SmithBarney("SmithBarney.hf", "SmithBarney.nf", 8, 8); InitializeClientHeaderFile(SmithBarney.hfp);

bool Empty (long int HeaderNo);

What Are We Passing Empty? HeaderNo  Identify Which List

HeaderType * Headers; DLNode * Nodes; NodePtr Avail; unsigned long int MaxNodes, MaxHeaders; Headers // // // // F R L InfoDR / T T T T T T T T Nodes DLList Sears(4, 8); How Do We Know If EMPTY?

Code Empty For Internal Memory

5 Nodes Available void GetNode (void);

Avail

DA_DLList Inventory ("Inventory.hf", "Inventory.nf", 4, 7); All 7 Nodes Start Out In The Available Pool Graphical Representation Of Available Pool

2 Valid Nodes & 5 Deleted Nodes Note Avail and Rec[0].Right Graphical Representation Of Available Pool

2 Valid Nodes & 5 Deleted Nodes Note Avail and Rec[0].Right Graphical Representation Of Available Pool You should be able to trace the Nodes In The Available Pool You should be able to sketch a graphical view of the Available Pool

Graphical Representation Of Header[2]

You should be able to trace the Nodes In The Available Pool You should be able to sketch a graphical view of the Available Pool

NodePtr GetNode(void); typedef long int NodePtr;

Let’s Just Chase The Concept Of GetNode When The List Begins Empty #1 GetNode – Returns 1

Let’s Just Chase The Concept Of GetNode When The List Begins Empty #2 GetNode – Returns 2

Let’s Just Chase The Concept Of GetNode When The List Begins Empty #3 GetNode – Returns 3

Let’s Just Chase The Concept Of GetNode When The List Begins Empty #4 GetNode – Returns 4

Let’s Just Chase The Concept Of GetNode When The List Begins Empty #5 GetNode – Returns 5

Let’s Just Chase The Concept Of GetNode When The List Begins Empty #6 GetNode – Returns 6

Let’s Just Chase The Concept Of GetNode When The List Begins Empty #7 GetNode – Returns 7

Let’s Just Chase The Concept Of GetNode When The List Begins Empty #8 GetNode – Returns ? INTERNAL MEMORY IMPLEMENTATION

Let’s Just Chase The Concept Of GetNode When The List Begins Empty #8 GetNode – Returns ? Direct Access File Implementation

Let’s Just Chase The Concept Of GetNode When The List Begins Empty #8 GetNode – Returns 1

Looking At The Nodes As We Construct Them Can Really Provide A Skewed Perception Of Reality & Lead To An Incorrect Algorithm. In Reality, Nodes In The Available Pool Will Come & Go, But They Will Seldom Be In Numerical Order. You Are Much More Likely To See Something Like The Following:

2 Valid Nodes & 5 Deleted Nodes Note Avail and Rec[0].Right

GetNode Solve The General Case First We Would Like To Return A Pointer To The First Node In The Available Pool. Ptr = Sears.GetNode();

DLList Sears (4,8); Ptr = Sears.GetNode(); NewNodePtr  1

DLList Sears (4,8); Ptr = Sears.GetNode(); NewNodePtr  1 

DLList Sears (4,8); Ptr = Sears.GetNode(); NewNodePtr  1 

Return WHAT? NewNodePtr  1 

Solved General Case

GetNode Special Cases? No More Nodes In The Available Pool!

GetNode Returns ?

GetNode – Returns 8

Let’s Just Chase The Concept Of GetNode When The List Begins Empty #8 GetNode – Returns ? Direct Access File Implementation

Let’s Just Chase The Concept Of GetNode When The List Begins Empty #8 GetNode – Returns ? INTERNAL MEMORY IMPLEMENTATION You Know Enough About Internal Memory To Do The Deep Copy Resize Function On Your Own. Please Do. It Will Not Be Available Today!

Code GetNode For Internal Memory

5 Nodes Available void FreeNode (NodePtr OldNodePtr);

FreeNode(7)

FreeNode(2)

FreeNode(4)

FreeNode(6)

FreeNode(1)

FreeNode Error Processing?

Code FreeNode For Internal Memory

PUSH bool Push (long int HeaderNo, InfoType NewInfo);

Push Solve The General Case First Push One On To The Front Of A List  Sears.Push (3, Mac);

DLList Sears(25, 1000);  Sears.Push (3, Mac);

DLList Sears(25, 1000);  Sears.Push (3, Mac);

DLList Sears(25, 1000);  Sears.Push (3, Mac); NewNodePtr = 4

DLList Sears(25, 1000);  Sears.Push (3, Mac); NewNodePtr = 4

DLList Sears(25, 1000);  Sears.Push (3, Mac);

DLList Sears(25, 1000);  Sears.Push (3, Mac);

DLList Sears(25, 1000);  Sears.Push (3, Mac);

DLList Sears(25, 1000);  Sears.Push (3, Mac);

DLList Sears(25, 1000);  Sears.Push (3, Mac);

DLList Sears(25, 1000);  Sears.Push (3, Mac);

Solved General Case

Push Special Cases? Push The First On A List

Push Error Processing?

Code Push For Internal Memory

POP bool Pop (long int HeaderNo, InfoType & OldInfo); OldInfo Is Info Previously At Front Of List

Pop Solve The General Case First Part P;  Sears.Pop (3, P); Pop One Off The Front Of A List P

Part P;  Sears.Pop (3, P); NodePtr OldFront; DLList Sears(25, 1000);

Part P;  Sears.Pop (3, P); NodePtr NewFront; DLList Sears(25, 1000);

Part P;  Sears.Pop (3, P); DLList Sears(25, 1000); OldInfo

Part P;  Sears.Pop (3, P); DLList Sears(25, 1000);

Part P;  Sears.Pop (3, P); DLList Sears(25, 1000);

Part P;  Sears.Pop (3, P); DLList Sears(25, 1000);

Part P;  Sears.Pop (3, P); DLList Sears(25, 1000);

Solved General Case

Pop Special Cases? Last On A List

Pop Error Processing?

Code Pop For Internal Memory

INSERT Bool Insert (long int HeaderNo, InfoType NewInfo);

Insert Solve The General Case First Push One On To The Rear Of A List  Sears.Insert (3, Mac);

DLList Sears(25, 1000);  Sears.Insert (3, Mac);

DLList Sears(25, 1000);  Sears.Insert (3, Mac);

DLList Sears(25, 1000);  Sears.Insert (3, Mac); NewNodePtr = 4

DLList Sears(25, 1000);  Sears.Insert (3, Mac); NewNodePtr = 4

DLList Sears(25, 1000);  Sears.Insert (3, Mac); NewNodePtr = 4

DLList Sears(25, 1000);  Sears.Insert (3, Mac); NewNodePtr = 4

DLList Sears(25, 1000);  Sears.Insert (3, Mac); NewNodePtr = 4

DLList Sears(25, 1000);  Sears.Insert (3, Mac); NewNodePtr = 4

DLList Sea rs(25, 1000);  Sears.Insert (3, Mac); NewNodePtr = 4

Solved General Case

Insert Special Cases? Insert The First On A List

Insert Error Processing?

Code Insert For Internal Memory

REMOVE bool Remove (long int HeaderNo, InfoType & OldInfo); OldInfo Is Info Previously At Rear Of List

Part P;  Sears.Remove (3, P); DLList Sears(25, 1000); OldInfo

Didn't I Just Write A Function Which Returns The Item On The Front Of A List? bool Remove (long int HeaderNo, InfoType & OldInfo); bool Pop (long int HeaderNo, InfoType & OldInfo);

Part P;  Sears.Remove (3, P); DLList Sears(25, 1000);

Philosophical Using List As A Stack  Push, Pop, Empty Using List As A Queue  Insert Remove, Empty

Code Remove For Internal Memory

InsertAfter bool InsertAfter(long int HeaderNo, InfoType & OldInfo, NodePtr LeftBrother);

InsertAfter Solve The General Case First InsertAfter One In The Middle Of A List

 Sears.InsertAfter (3, 1, Mac); DLList Sears(25, 1000);

DLList Sears(25, 1000);  Sears.InsertAfter (3, 1, Mac);

DLList Sears(25, 1000);

DLList Sears(25, 1000);  Sears.InsertAfter (3, 1, Mac);

DLList Sears(25, 1000);  Sears.InsertAfter (3, 1, Mac); NewNodePtr = 4

DLList Sears(25, 1000);  Sears.InsertAfter (3, 1, Mac); NewNodePtr = 4 NodePtr RightBrother;

DLList Sears(25, 1000);  Sears.InsertAfter (3, 1, Mac); NewNodePtr = 4

DLList Sears(25, 1000);  Sears.InsertAfter (3, 1, Mac); NewNodePtr = 4

DLList Sears(25, 1000);  Sears.InsertAfter (3, 1, Mac); NewNodePtr = 4

DLList Sears(25, 1000);  Sears.InsertAfter (3, 1, Mac); NewNodePtr = 4

DLList Sears(25, 1000);  Sears.InsertAfter (3, 1, Mac); NewNodePtr = 4

DLList Sears(25, 1000);  Sears.InsertAfter (3, 1, Mac); NewNodePtr = 4

DLList Sears(25, 1000);  Sears.InsertAfter (3, 1, Mac); NewNodePtr = 4

InsertAfter Special Cases? InsertAfter One At The Rear Of A List

InsertAfter Error Processing?

Code InsertAfter For Internal Memory

bool Inplace (long int HeaderNo, InfoType & OldInfo);

Inplace  Place First Element? Do You Have A Function That Would Place The First Element On A List? DLList Sears(25, 1000); Sears.Inplace(3, Asus);

Do You Have A Function That Would Place An Element At The Rear Of A List? DLList Sears(25, 1000); Sears.Inplace(3, Toshiba); Inplace  Place One On Rear?

DLList Sears(25, 1000); Sears.Inplace(3, Apple); Inplace  Place One On Front?

DLList Sears(25, 1000); Sears.Inplace(3, HP); Inplace  Place One On Front? ? 5 NodePtr LeadPtr 

DLList Sears(25, 1000); Sears.Inplace(3, HP); Inplace  Place One On Front? ? 5 NodePtr LeadPtr 