习题1
Chapter 1 P
18 1.7
1.7 Does every problem have an algorithm?
Every problem does not have an algorithm.
1.8
1.8 Does every algorithm have a C++ program?
By “algorithm” we mean something composed of steps are
of a nature that they can be performed by a computer. If so, than any algorithm
can be expressed in C++.
习题2
Chapter 4 P
135 4.3
4.3 Write a series of C++ statements to create a list capable of holding 20 elements and which actually stores the following list <2,3|15,5,9>.
Solution:
list L1(20);
L1.append(2);
L1.append(23);
L1.append(15);
L1.append(5);
L1.append(9);
L1.next();
L1.next();
4.4
4.4 Write a function to interchange the first two elements in the right partition of a list.
Solution:
void switch(List<Elem> L1) {
Elem temp;
if (!L1.remove(temp)) ERROR;
L1.next();
L1.insert(temp);
}
4.5
4.5 Add to the LList class implementation a member function to reverse the order of the elements on the list,run time
⊙(n).
template <class Elem>
void LList<Elem>::reverse() { // Reverse list contents
if(head->next == NULL) return;
// First, fix f