You are to implement a class intCHDList as a single file intCHDList.cpp. The cla
ID: 3531955 • Letter: Y
Question
- You are to implement a class intCHDList as a single file intCHDList.cpp.
- The class creates circular, headed, doubly-linked lists of integers to implement the list functions.
- No other implementation is acceptable
- use the DLnode class as the nodes your list.
- You will uncomment lines in each test to show your list class can do that function.
-
-
- //MAIN PROGRAM PROGRAM4
-
- #include <iostream> #include <list> #include "intCHDList.cpp" // uncomment this for final
using namespace std;
// display the values of nodes in the list void printIntList(list<int> l) { cout << " ["; list<int>::iterator it; for(it=l.begin(); it != l.end(); ++it) cout << *it << " "; cout << "] "; }
// display the addresses of nodes in the list void locDisplay(list<int> l) { cout << "["; list<int>::iterator it; for(it=l.begin(); it != l.end(); ++it) cout << &it << " "; cout << "] "; }
int main() {
// create a list of integers cout << " --- initializing list" << endl; list<int> iList; // intCHDList mList; // uncomment this for final cout << " C++ list is "; printIntList(iList); // cout <<"and has size: " << iList.size() << " is Empty?: " << iList.empty() << endl; // cout << " >>> My list is "; //uncomment this for final // mList.display(); // uncomment for final // cout << " and has size: "<< mList.size() << " is Empty?: " << mList.empty() << endl; // uncomment this for final
// insert 0..4 in orderinto the list, report list size and show filled list // cout << endl << " --- inserting 0..4 at end of list" << endl; for (int i=0 ; i<5; i++) { iList.push_back(i); // mList.insert(i,i); // uncomment this for final } cout << " C++ list is now "; printIntList(iList); cout << " and has size " << iList.size() << endl; // cout << " >>> my list is now: "; //uncooment for final // mList.display(); // uncomment this and next for final // cout <<" and has size: " << mList.size() << endl;
// to search for the ith element in the C++ list cout << endl <<" ---Looking for [2] element in list" << endl; int i=1; list<int>::iterator it; // iterator is our only indexed access to list!! for (it=iList.begin(); i<3; i++, it++); cout << "The [2] element in the C++ list has value " << * it << endl; // cout << ">>> The [2] element in my list has value " << mList.get(2)->value << endl; // uncomment ths for final
// remove the found element from the list cout << endl << " --- deleting [2] element in the list" << endl; cout << " C++ list is now: "; iList.remove(* it); printIntList(iList); cout << endl; // cout << ">>> my list is now: "; //uncomment for final // mList.dele(2); //uncomment for final // mList.display(); //uncomment for final // cout << endl; //uncomment for final
// insert a new element as the third in the list cout << endl << " --- inserting 5 as the [2] item in the list" << endl; for(it=iList.begin(), i=1; it != iList.end() && i<3; ++it, i++); // access 2nd by iteratorr iList.insert(it,5); // using pointer found above cout << " C++ list is now: "; printIntList(iList); cout << endl; // mList.insert(5,2); //uncomment for final // cout << " >>> my list is now: "; //uncomment for final // mList.display(); //uncomment for final // cout << endl; //uncomment for final
// show the actual nodes in the lists cout << endl << " --- inspecting structures by showing data node addresses" << endl; locDisplay(iList); cout << endl; // mList.locDisplay(); //uncomment for final // cout << endl; //uncomment for final
/* the operations of the C++ list class make it easier to operate with values rather than locations in sequence - we give examples of two here: */ // delete the value 4 cout << endl << " --- removing the VALUE 4" <<endl; iList.remove(4); cout << " C++ list is now"; printIntList(iList); cout << endl; // mList.remove(4); //uncomment for final // cout << " >>> my list is now: "; //uncomment for final // mList.display(); //uncomment for final // cout << endl; //uncomment for final
system("pause"); return 0; }
//DLNODE CLASS
class DLnode { public :
int value; DLnode * next ; DLnode * previous;
DLnode() { next = previous = 0; value=0; }
DLnode(int val){ next = previous = 0; value = val; }
DLnode (int val, DLnode * nxt, DLnode * prv){ value = val; next = nxt; previous = prv; }
};
- #include <iostream> #include <list> #include "intCHDList.cpp" // uncomment this for final
using namespace std;
// display the values of nodes in the list void printIntList(list<int> l) { cout << " ["; list<int>::iterator it; for(it=l.begin(); it != l.end(); ++it) cout << *it << " "; cout << "] "; }
// display the addresses of nodes in the list void locDisplay(list<int> l) { cout << "["; list<int>::iterator it; for(it=l.begin(); it != l.end(); ++it) cout << &it << " "; cout << "] "; }
int main() {
// create a list of integers cout << " --- initializing list" << endl; list<int> iList; // intCHDList mList; // uncomment this for final cout << " C++ list is "; printIntList(iList); // cout <<"and has size: " << iList.size() << " is Empty?: " << iList.empty() << endl; // cout << " >>> My list is "; //uncomment this for final // mList.display(); // uncomment for final // cout << " and has size: "<< mList.size() << " is Empty?: " << mList.empty() << endl; // uncomment this for final
// insert 0..4 in orderinto the list, report list size and show filled list // cout << endl << " --- inserting 0..4 at end of list" << endl; for (int i=0 ; i<5; i++) { iList.push_back(i); // mList.insert(i,i); // uncomment this for final } cout << " C++ list is now "; printIntList(iList); cout << " and has size " << iList.size() << endl; // cout << " >>> my list is now: "; //uncooment for final // mList.display(); // uncomment this and next for final // cout <<" and has size: " << mList.size() << endl;
// to search for the ith element in the C++ list cout << endl <<" ---Looking for [2] element in list" << endl; int i=1; list<int>::iterator it; // iterator is our only indexed access to list!! for (it=iList.begin(); i<3; i++, it++); cout << "The [2] element in the C++ list has value " << * it << endl; // cout << ">>> The [2] element in my list has value " << mList.get(2)->value << endl; // uncomment ths for final
// remove the found element from the list cout << endl << " --- deleting [2] element in the list" << endl; cout << " C++ list is now: "; iList.remove(* it); printIntList(iList); cout << endl; // cout << ">>> my list is now: "; //uncomment for final // mList.dele(2); //uncomment for final // mList.display(); //uncomment for final // cout << endl; //uncomment for final
// insert a new element as the third in the list cout << endl << " --- inserting 5 as the [2] item in the list" << endl; for(it=iList.begin(), i=1; it != iList.end() && i<3; ++it, i++); // access 2nd by iteratorr iList.insert(it,5); // using pointer found above cout << " C++ list is now: "; printIntList(iList); cout << endl; // mList.insert(5,2); //uncomment for final // cout << " >>> my list is now: "; //uncomment for final // mList.display(); //uncomment for final // cout << endl; //uncomment for final
// show the actual nodes in the lists cout << endl << " --- inspecting structures by showing data node addresses" << endl; locDisplay(iList); cout << endl; // mList.locDisplay(); //uncomment for final // cout << endl; //uncomment for final
/* the operations of the C++ list class make it easier to operate with values rather than locations in sequence - we give examples of two here: */ // delete the value 4 cout << endl << " --- removing the VALUE 4" <<endl; iList.remove(4); cout << " C++ list is now"; printIntList(iList); cout << endl; // mList.remove(4); //uncomment for final // cout << " >>> my list is now: "; //uncomment for final // mList.display(); //uncomment for final // cout << endl; //uncomment for final
system("pause"); return 0; }
//DLNODE CLASS
class DLnode { public :
int value; DLnode * next ; DLnode * previous;
DLnode() { next = previous = 0; value=0; }
DLnode(int val){ next = previous = 0; value = val; }
DLnode (int val, DLnode * nxt, DLnode * prv){ value = val; next = nxt; previous = prv; }
}; #include <iostream> #include <list> #include "intCHDList.cpp" // uncomment this for final
using namespace std;
// display the values of nodes in the list void printIntList(list<int> l) { cout << " ["; list<int>::iterator it; for(it=l.begin(); it != l.end(); ++it) cout << *it << " "; cout << "] "; }
// display the addresses of nodes in the list void locDisplay(list<int> l) { cout << "["; list<int>::iterator it; for(it=l.begin(); it != l.end(); ++it) cout << &it << " "; cout << "] "; }
int main() {
// create a list of integers cout << " --- initializing list" << endl; list<int> iList; // intCHDList mList; // uncomment this for final cout << " C++ list is "; printIntList(iList); // cout <<"and has size: " << iList.size() << " is Empty?: " << iList.empty() << endl; // cout << " >>> My list is "; //uncomment this for final // mList.display(); // uncomment for final // cout << " and has size: "<< mList.size() << " is Empty?: " << mList.empty() << endl; // uncomment this for final
// insert 0..4 in orderinto the list, report list size and show filled list // cout << endl << " --- inserting 0..4 at end of list" << endl; for (int i=0 ; i<5; i++) { iList.push_back(i); // mList.insert(i,i); // uncomment this for final } cout << " C++ list is now "; printIntList(iList); cout << " and has size " << iList.size() << endl; // cout << " >>> my list is now: "; //uncooment for final // mList.display(); // uncomment this and next for final // cout <<" and has size: " << mList.size() << endl;
// to search for the ith element in the C++ list cout << endl <<" ---Looking for [2] element in list" << endl; int i=1; list<int>::iterator it; // iterator is our only indexed access to list!! for (it=iList.begin(); i<3; i++, it++); cout << "The [2] element in the C++ list has value " << * it << endl; // cout << ">>> The [2] element in my list has value " << mList.get(2)->value << endl; // uncomment ths for final
// remove the found element from the list cout << endl << " --- deleting [2] element in the list" << endl; cout << " C++ list is now: "; iList.remove(* it); printIntList(iList); cout << endl; // cout << ">>> my list is now: "; //uncomment for final // mList.dele(2); //uncomment for final // mList.display(); //uncomment for final // cout << endl; //uncomment for final
// insert a new element as the third in the list cout << endl << " --- inserting 5 as the [2] item in the list" << endl; for(it=iList.begin(), i=1; it != iList.end() && i<3; ++it, i++); // access 2nd by iteratorr iList.insert(it,5); // using pointer found above cout << " C++ list is now: "; printIntList(iList); cout << endl; // mList.insert(5,2); //uncomment for final // cout << " >>> my list is now: "; //uncomment for final // mList.display(); //uncomment for final // cout << endl; //uncomment for final
// show the actual nodes in the lists cout << endl << " --- inspecting structures by showing data node addresses" << endl; locDisplay(iList); cout << endl; // mList.locDisplay(); //uncomment for final // cout << endl; //uncomment for final
/* the operations of the C++ list class make it easier to operate with values rather than locations in sequence - we give examples of two here: */ // delete the value 4 cout << endl << " --- removing the VALUE 4" <<endl; iList.remove(4); cout << " C++ list is now"; printIntList(iList); cout << endl; // mList.remove(4); //uncomment for final // cout << " >>> my list is now: "; //uncomment for final // mList.display(); //uncomment for final // cout << endl; //uncomment for final
system("pause"); return 0; }
//DLNODE CLASS
class DLnode { public :
int value; DLnode * next ; DLnode * previous;
DLnode() { next = previous = 0; value=0; }
DLnode(int val){ next = previous = 0; value = val; }
DLnode (int val, DLnode * nxt, DLnode * prv){ value = val; next = nxt; previous = prv; }
}; class DLnode { public :
int value; DLnode * next ; DLnode * previous;
DLnode() { next = previous = 0; value=0; }
DLnode(int val){ next = previous = 0; value = val; }
DLnode (int val, DLnode * nxt, DLnode * prv){ value = val; next = nxt; previous = prv; }
};
Explanation / Answer
May someone please post intCHDList.cpp?
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.