CS2134-Homework 6- Draw the conceptual representation for our implementation of a link list Solved

40.00 $ 20.00 $

Category:
Click Category Button to View Your Next Assignment | Homework

You'll get a download link with a: . zip solution files instantly, after Payment

Description

Rate this product

HOMEWORK 6

Written Part:
1. Draw the conceptual representation for our implementation of a link list (include the header) containing a single item A.
2. For each of the following, determine if the code compiles.
vector A = {1,2,3,4,5}; vector::iterator vItr1; vector::iterator vItr2; list C = {1, 2,3,4,5}; list::iterator lItr1; list::iterator lItr2;
(a)
vItr1 = A.begin( ); vItr2 = A.end( );
cout << vItr1 + (vItr1 + vItr2)/2;
(b) lItr1 = C.begin( ); lItr2 = find(C.begin(), C.end(), 3); if ( lItr1 < lItr2 ) cout << " 2 is not the first item ";
3. For each of the following, determine if the iterator is valid.
vector A = {1,2,3,4,5}; vector B; vector::iterator vItr; list C = {1, 2,3,4,5}; list D; list::iterator lItr;
(a) B = A; vItr = B.begin();
B.erase(B.begin()+1);
(b) B = A;
vItr = B.begin()+2;
B.erase(B.begin()+1);
(c) D = C; lItr = C.begin();
C.erase(++C.begin());
(d) D = C;
lItr = ++D.begin();
++lItr
D.erase(++D.begin());
4. Which of the following code snippets are valid? If the code snippet is invalid, state why.
(a) list l; list::iterator lIter; l.push_back(200); lIter = l.begin(); for (int i = 1; i < 100; ++i)
l.push_front(i);
for (int i = 1; i < 100; ++i)
l.push_back(-i);
cout << *lIter << endl;
(b) list l; list::iterator lIter1; list::iterator lIter2; list::iterator mid;
for (int i = 0; i < 100; ++i)
l.push_back(i); lIter1 = l.begin(); lIter2 = l.end(); mid = lIter1 + (lIter2 – lIter1)/2; cout << *mid << endl;
(c) vector v; vector::iterator vIter1; vector::iterator vIter2; vector::iterator mid;
for (int i = 0; i < 100; ++i)
v.push_back(i);
vIter1 = v.begin(); vIter2 = v.end(); mid = vIter1 + (vIter2 – vIter1)/2; cout << *mid <next; while ( prev != nullptr )
{ if ( prev->next->data == x ) erase_after( iterator(prev) );
else prev = prev->next;
}
}

  • Homework-6-tqf0uk.zip