Presentation is loading. Please wait.

Presentation is loading. Please wait.

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.

Similar presentations


Presentation on theme: "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."— Presentation transcript:

1 1

2

3

4 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

5

6

7

8

9

10

11

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

13 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

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

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

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

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

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

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

20 Double Linked Lists - Meet The Specification ?

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

22

23 23

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

25 typedef long int NodePtr;

26 Need 3 Classes

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

28 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; };

29 DLNode

30

31

32 Base Header Class

33 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; };

34 ListHeader

35

36 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; };

37 PartListHeader

38 Snapshot Of Inventory System Header File

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

40 Sketch List No-1 10 2 3 3 30 2 4 40 4 3 F R # 32 4 1

41 Sketch List No-2 F R # 11 1 2 20 1

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

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

44

45

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

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

48 HeaderType * Headers; DLNode * Nodes; NodePtr Avail; unsigned long int MaxNodes, MaxHeaders; 4 8 1 Headers 0 1 2 3 4 // // // // F R 0 1 2 3 4 5 6 7 8 L InfoDR / 8 7 6 5 4 3 2 1 T T T T T T T T Nodes DLList Sears(4, 8);

49 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. 1 0 1 2 3 4 5 6 7 8 L InfoDR / 8 7 6 5 4 3 2 1 T T T T T T T T Nodes

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

51 DLNode * Nodes; NodePtr Avail; unsigned long int MaxNodes, 0 1 2 3 4 5 6 7 8 L InfoDR Nodes DLList Sears(4, 8);  Constructor  CreateNodes();

52 0 1 2 3 4 5 6 7 8 L InfoDR Nodes DLNode * Nodes; NodePtr Avail; unsigned long int MaxNodes, DLList Sears(4, 8);  Constructor  CreateNodes(); 0 1 2 3 4 5 6 7 8 L InfoDR / 8 7 6 5 4 3 2 1 T T T T T T T T Nodes

53 DLNode * Nodes; NodePtr Avail; unsigned long int MaxNodes, DLList Sears(4, 8);  Constructor  CreateNodes(); 0 1 2 3 4 5 6 7 8 L InfoDR / 8 7 6 5 4 3 2 1 T T T T T T T T Nodes ? 8

54 DLNode * Nodes; NodePtr Avail; unsigned long int MaxNodes, DLList Sears(4, 8);  Constructor  CreateNodes(); 0 1 2 3 4 5 6 7 8 L InfoDR / 8 7 6 5 4 3 2 1 T T T T T T T T Nodes 8 ? 1

55 Code CreateNodes For Internal Memory

56 HeaderType * Headers; unsigned long int MaxHeaders;

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

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

59 Code CreateHeaders For Internal Memory

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

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

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

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

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

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

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

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

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

69 bool Empty (long int HeaderNo);

70 What Are We Passing Empty? HeaderNo  Identify Which List

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

72 Code Empty For Internal Memory

73 5 Nodes Available void GetNode (void);

74 Avail

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

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

77 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

78 Graphical Representation Of Header[2]

79 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

80 NodePtr GetNode(void); typedef long int NodePtr;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

97 Return WHAT? NewNodePtr  1 

98 Solved General Case

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

100 GetNode Returns ?

101

102

103

104 GetNode – Returns 8

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

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

107 Code GetNode For Internal Memory

108 5 Nodes Available void FreeNode (NodePtr OldNodePtr);

109 FreeNode(7)

110 FreeNode(2)

111 FreeNode(4)

112 FreeNode(6)

113 FreeNode(1)

114 FreeNode Error Processing?

115 Code FreeNode For Internal Memory

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

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

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

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

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

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

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

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

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

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

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

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

128 Solved General Case

129 Push Special Cases? Push The First On A List

130 Push Error Processing?

131 Code Push For Internal Memory

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

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

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

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

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

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

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

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

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

141 Solved General Case

142 Pop Special Cases? Last On A List

143 Pop Error Processing?

144 Code Pop For Internal Memory

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

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

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

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

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

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

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

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

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

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

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

156 Solved General Case

157 Insert Special Cases? Insert The First On A List

158 Insert Error Processing?

159 Code Insert For Internal Memory

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

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

162 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);

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

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

165 Code Remove For Internal Memory

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

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

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

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

170 DLList Sears(25, 1000);

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

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

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

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

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

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

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

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

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

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

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

182 InsertAfter Error Processing?

183 Code InsertAfter For Internal Memory

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

185 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);

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

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

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

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


Download ppt "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."

Similar presentations


Ads by Google