We are being introduced to ADT's with type LIST. I initially thought LIST was included in some C++ library with predefined functions such as .insert(), .retrieve(), .getLength(), isEmpty() and so on. I now suspect this is all created by the programmer with classes and header files........which we'll cover shortly. Confused as usual, this is what I "get" so far:

Grocery list analogy: milk, bread, coffee, rolls

alist.insert(1, milk, success)
alist.insert(2, bread, success)
alist.insert(3, coffee, success)
alist.insert(1, rolls, success) YIELDS:


I have been attempting to understand how to write code to simulate such a list to no avail. I've abandoned that notion for the homework, which asks that we only write on paper with no need to test or compile a C++ function with a parameter ADT List object called "alist." The implementation should consist of calls to other functions of ADT List. We won't directly manipulate any member data????? Assume use of conventional ADT List member functions used in C++ such as insert, remove, getLength etc.
First, "consider" a list of integers and write function that computes the sum of integers in "alist." The function definition must be independent of the list's implementation.

Then I have to write some "swap" function that will reverse the order of some ADT list, but not "write swap()" "just use it!" ?????
I thought that C++ automatically "sums" lists somehow, and that should therefore make it easy to output some sum of some list.......
Thoroughly confused as usual, have brick close to forehead

>I initially thought LIST was included in some C++ library
It is, but it's called list rather than LIST.

>I thought that C++ automatically "sums" lists somehow
Yea, C++ supports that with the library too. It's called accumulate.

>Thoroughly confused as usual
I'm not entirely sure what you're asking for either.

<<<"I'm not entirely sure what you're asking for either......
Thanks Narue. I just need to write (on paper), a function that would 'sum' some implied list.
Then, I need to write a function that would reverse the order of some implied list; and I quote, "using some swap() function - but don't write swap(), just use it." Apparently, the latter exercise is tied to another exercise that we were not assigned, in which one was asked to construct a function called swap() to interchange items at different positions on a list. As far as my profs. instructions on "just write swap(), don't use it" I am completely baffled. Perhaps it sufficient to provide pseudocode that will reverse implied list .alist. For the first one, would I simply write a alist.retrieve()? Or would I utilize this accumulate somehow? Also, I would really like to build a simple list so I can compile it, but have no clear code example in my text demonstrating this>>Please help Narue

I think this might be sufficient:

for(position = 1 through alist.getLength())
x = getSum
Display x

And to reverse a list without defining a function known as swap:

for(position =1 through alist.getLength())

alist.Swap(position(s), data, success)
Display data
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.