C++ DCList Class Using your knowledge of Circular and Doubly-Linked list algorit
ID: 3865550 • Letter: C
Question
C++ DCList Class
Using your knowledge of Circular and Doubly-Linked list algorithms, create a new class combining the two into a new data structure: a Circular, Doubly-Linked List. Call the class DCList and place it in it's own header file, DCList.h. Your class must implement the methods as described in the above UML diagram.
The following methods should be included in your class:
constructor - initializes pointers in the class to NULL.
destructor - destroys the linked list.
clear - destroys the linked list, resetting pointers to NULL.
insert - inserts it's argument into the list, maintaining an ascending order. Returns 0 on success, -1 on failure.
append - attached it's argument to the end of the list.
remove - removes the the first node containing it's argument from the list. Returns 0 on success, -1 on failure.
isFull - returns true if the list is full, false otherwise.
isEmpty - returns true if the list is empty, false otherwise.
print - displays the content of the list to the screen on a single line. Each value is separated by a space.
reverse - displays the content of the list to the screen on a single line, but in reverse order.
next - displays the "next" value in the list. It does this by advancing the cur pointer and then assigning the node's value to next's reference parameter. Returns 0 on success, -1 on failure.
length - returns the number of nodes in the list.
Hints:
Re-use methods when you can.
PLEASE DO NOT POST THE BAD CODE FLOATING AROUND FOR THIS
Explanation / Answer
The required header file for the above UML diagram is as follows.The header file consists of all the above methods in the description. Hope it was helpful...
DCList.h
#ifndef DCLIST
#define DCLIST
#define CSTDEF
#define CSTDLIB
const unsigned int EOFListIndex = OFstatic_cast(unsigned int, -1L);
class DcmObj;
class Node {
friend class DCMLists;
Node *next;
Node *prev;
DcmObj *objNodeValue;
Node(const Node &);
Node &ops=(const Node &);
public:
Node( DcmObj *object );
~Node();
inline DcmObj *value() { return objNodeValue; }
};
typedef enum
{
pos,
first,
last,
previous,
nxt
} listPosit;
class DCMLists {
Node *first;
Node *last;
Node *curr;
unsigned int crd;
DCMLists &ops=(const DCMLists &);
DCMLists(const DCMLists &newList);
public:
DCMLists();
~DCMLists();
DcmObj *append( DcmObj *object )
{
arr.insert(arr.end(),arr1.begin(),arr.end());
}
DcmObj *reverse( DcmObj *object )
{
while(curr != NULL)
{
nxt = curr -> nxt;
curr -> nxt = prev;
prev = curr;
curr = nxt;
}
*pos = prev;
}
DcmObj *insert( DcmObj *object,listPosit pos = nxt )
{
while (ptr -> nxt!=NULL)
{
ptr = ptr -> nxt;
}
}
DcmObj *clear()
{
while(curr != NULL)
{
if(curr == NULL)
break;
else
{
temp = curr;
curr = curr -> nxt;
delete temp;
}
}
}
DcmObj *next()
{
int cnt = 0;
while(curr != NULL)
{
if(cnt != NULL)
return(curr!=NULL);
cnt++;
curr = curr -> nxt;
}
assert(0);
}
DcmObj *remove()
{
*first = temp -> nxt;
free(tmp);
return;
}
DcmObj *seek( listPosit pos = nxt )
{
if(curr!=NULL)
{
search = curr;
curr = curr -> nxt;
cout << search;
}
}
DcmObj *length()
{
Node* b = K;
while (b!=NULL)
{
++cnt;
b = b -> nxtptr;
}
}
inline OFBool isFull(void) const
{
return last != NULL;
}
inline OFBool isEmpty(void) const
{
return first == NULL;
}
inline OFBool isValid(void) const
{
return curr != NULL;
}
};
Please rate the answer if it helped......Thankyou
Hope it helps......
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.