Anyone here a guru in c++, need help with hw that involves doubly linked lists. Will compensate for help.
>>207458
post a better pic,not clear
#include <iostream>
using namespace std;
class Item
{
public:
int val;
Item *next, *pre;
Item()
{
val = 0;
next = 0;
pre = 0;
}
Item(int val)
{
this->val = val;
next = 0;
pre = 0;
}
};
class DLinkedList
{
int size;
Item *front;
Item *back;
public:
DLinkedList();
DLinkedList(const DLinkedList &list);
void push_back(Item *a);
void push_front(Item *a);
Item * pop_front();
Item * pop_back();
void insert(Item *a, int t); // insert the item a after the t-th element
void insertlist(DLinkedList *list, int t); // insert the whole list a after the t-th element
void display(ostream &out);
int getSize();
Item * getfront();
Item * getback();
void swap(Item *p, Item *q); //swap two items pointed by p and q, you can assume that p and q are something in the list
Item * extractmin(Item * start); // return the pointer of the min element after "start",
// here you can assume user will always input a valid pointer start that points to an item in the list
Item * extractmax(Item * start); // return the pointer of the max element after "start"
};
class myStack
{
DLinkedList list;
public:
myStack();
int getSize();
void in(Item *a);
Item *top();
void out();
};
class myQueue
{
DLinkedList list;
public:
myQueue();
int getSize();
void in(Item *a);
Item *front();
void out();
};
int main() {
system("pause");
return 0;
}
Task 1: Implement the constructors (default and copy) of DLinkedList. You need to make sure
that the copy constructor makes a separate copy of the list.
Task 2: Implement push back, push front, pop back, pop front, get front, get back, display, swap.
The functions are pretty self explanatory from their names.
Task 3: Implement Inserts. You should handle “insert an item” and “insert a list”.
Task 4: Implement extract min, extract max. They return the pointer to the min/max item in
the list. If there is a tie, then choose arbitrarily among the mins/maxes. (Explain your choice in
the writeup).
Task 5: Implement classes myQueue and myStack using DLinkedList. Do not re-write codes.
(This task is pretty easy).
Task 6: Design a test function to test your DLinkedList. You don’t need to test your Stack nor
Queue, as checking them is easy, assuming your DLinkedList is correct.
I have a few questions, if anyone thinks they can help, please reply, will compensate with $$
>>207480
Shoot it.
>>207480
I haven't thoroughly tested this, but this should do what you want:
http://pastebin.com/5TEKXBsa