Purchase Solution

Tranfer an array to a list

Not what you're looking for?

Ask Custom Question

Consider the C++ array

int arr[] = (-15, 5, 35, -19, -12, 17, -4);

int arrSize = sizeof(arr)/sizeof(int);

(a) Declare the list object intList that holds the integers from the array arr.
(b) Declare the iterator iter for an integer list.
(c) Initialize the iterator iter to the beginning of the list intList.
(d) Assume iter is set to the start of the list.

iter++;
iter++; // what value does iter point at?
cout << *iter; // what is the output?
iter = intList.end();
iter--;
iter--; // what value does iter point at?
cout << *iter; // what is the output?
iter = intList.end();
iter++; // what value does iter point at?
cout << *iter; // what is the output?

(e) Use the iterator to write a code segment that scans the list elements and replaces each negative value by the corresponding positive number.

Please provide a complete program if it makes sense.

Purchase this Solution

Solution Summary

Create a list based on an array, and scan the elements using iterator.

Purchase this Solution


Free BrainMass Quizzes
Inserting and deleting in a linked list

This quiz tests your understanding of how to insert and delete elements in a linked list. Understanding of the use of linked lists, and the related performance aspects, is an important fundamental skill of computer science data structures.

Javscript Basics

Quiz on basics of javascript programming language.

C++ Operators

This quiz tests a student's knowledge about C++ operators.

Basic Computer Terms

We use many basic terms like bit, pixel in our usual conversations about computers. Are we aware of what these mean? This little quiz is an attempt towards discovering that.

Word 2010: Table of Contents

Ever wondered where a Table of Contents in a Word document comes from? Maybe you need a refresher on the topic? This quiz will remind you of the keywords and options used when working with a T.O.C. in Word 2010.