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