Upload
vignesvaran
View
215
Download
0
Embed Size (px)
Citation preview
7/21/2019 29938 Lab 07 the Linked List as a Data Structure
1/4
Lab 07 The Linked List as a Data Structure
Exercise 1: Understanding the Vector Class (0 !in"
The C## $ector class has the %ollo&ing ' !ethods: size() )eturns the nu!ber o% ele!ents in the $ector*
capacity() )eturns the nu!ber o% ele!ents that the $ector could contain &ithoutallocating !ore storage*
The %ollo&ing +rogra! inserts '0 ele!ents into a $ector* Then re!o$e one ele!ent %ro! the $ector at
a ti!e until the $ector is e!+t,* -ns&er the %ollo&ing .uestions:
i" /hen &ill the $ector increase its ca+acit,
ii" , ho& !uch does the $ector increase its ca+acit, each ti!e
iii" Does the $ector e$er decrease its ca+acit, auto!aticall,
#include #include #include #include // system("PAUS")!using namespace std!
int main() vector v! cout
7/21/2019 29938 Lab 07 the Linked List as a Data Structure
2/4
Exercise ': Creating a Linked List Structure (20 !in"
Use a 3ined3istclass to co!+lete the +rogra! belo& b, &riting the !ethods needed to +er%or!the %ollo&ing o+erations:
display4odes Dis+la, the list o% nodes*
insert5ront 3nserting a node to the beginning o% a list*
insert6ac 3nserting a node to the end o% a list*
insertAter 3nserting a node a%ter a target node*
searc Search %or a node %ro! a list (returns a boolean $alue"*
maempty E!+t, the list b, deleting all nodes*
#include #include using namespace std!
class Point int 7! int y!public8 Point (int 7 , %9 int y , %) 8 7(7)9 y(y) 0 riend ostream: operator> (istream: is9 Point: p) cout
7/21/2019 29938 Lab 07 the Linked List as a Data Structure
3/4
void insert5ront (: ne*lement) // Add code&
0
void insert6ac (: ne*lement) // Add code&
0
bool insertAter (: target9 : ne*lement) // Add code&
0
bool searc (: target) // Add code&
0
void maempty () // Add code&
0
riend ostream: operator
7/21/2019 29938 Lab 07 the Linked List as a Data Structure
4/4
list&insert6ac (ne*Point)! brea! case 8 cin >> target! ne*Point , Point(--seed9 seed)! ound , list&insertAter (target9 ne*Point)!
i (2ound) cout > target! ound , list&searc (target)! i (2ound) cout