Access over 35 million academic & study documents

A7q3 cc File#include iostream #include cstring #include

Content type
User Generated
Rating
Showing Page:
1/22
a7q3.cc File
#include <iostream>
#include <cstring>
#include \"ArrayList.h\"
using namespace std;
// Algorithm copy(s)
// Pre: s :: refToChar
// Post: memory allocated on heap to store a copy
// Return: reference to new string
char *copy(char *s) {
char *temp = new char[strlen(s)+1];
strcpy(temp,s);
return temp;
}
void test_ListOperations(){
cout << \"testing createList\" << endl;
List *myList = createList(10);
if (myList == NULL){
cout << \"createList failed\" << endl;
return;
} else{
cout << \"createList succeeded\" << endl;
}
cout << \"testing destroyList\" << endl;
destroyList(myList);
cout << \"testing destroyList succeeded\" << endl;
cout << \"testing emptyList with an empty list\" << endl;
myList = createList(10);
if (! emptyList(myList)){
cout << \"testing emptyList failed when an empty list was
given\"<< endl;

Sign up to view the full document!

lock_open Sign Up
Showing Page:
2/22
return;
}
cout << \"testing lengthList with an empty list\" << endl;
if (lengthList(myList) != 0){
cout << \"an empty list should have length 0\" << endl;
return;
}
cout << \"inserting an element at the tail of the list\" <<
endl;
char firstElement[] = \"first\";
char *toInsert = copy(firstElement);
if (!(insertTail(myList, toInsert))){
cout << \"insertTail failed to insert first element\" << endl;
return;
}
if (emptyList(myList)){
cout << \"testing emptyList failed when a non-empty list
was given\"<< endl;
return;
}
if (lengthList(myList) != 1){
cout << \"A list with 1 element should have length 1\"<<
endl;
return;
}
cout << \"inserting a second element at the tail of the list\"
<< endl;
char secondElement[] = \"second\";
toInsert = copy(secondElement);
if (!(insertTail(myList, toInsert))){
cout << \"insertTail failed to insert second element\" <<
endl;
return;
}
if (emptyList(myList)){
cout << \"testing emptyList failed when a non-empty list

Sign up to view the full document!

lock_open Sign Up
Showing Page:
3/22

Sign up to view the full document!

lock_open Sign Up
End of Preview - Want to read all 22 pages?
Access Now
Unformatted Attachment Preview
a7q3.cc File #include #include #include \"ArrayList.h\" using namespace std; // Algorithm copy(s) // Pre: s :: refToChar // Post: memory allocated on heap to store a copy // Return: reference to new string char *copy(char *s) { char *temp = new char[strlen(s)+1]; strcpy(temp,s); return temp; } void test_ListOperations(){ cout ...
Purchase document to see full attachment
User generated content is uploaded by users for the purposes of learning and should be used following Studypool's honor code & terms of service.

Anonymous
Nice! Really impressed with the quality.

Studypool
4.7
Indeed
4.5
Sitejabber
4.4