/* Is it possible that someone could give me a pseudo code for what I am suppose to do, step by step. The professor gave us 3 codes and also a infile in which I saved it as InkList.txt. She wants us to create a program as she stated in the .doc file about what we are suppose to do in C++. The class it self is struggling and I am most definitely. So if you understand her instructions, maybe you can help me and the class. Below are all the attachments I saved. Thanks! */
bmcutler011 0 Newbie Poster
#ifndef DOUBLY_LINKED_NODE_CLASS
#define DOUBLY_LINKED_NODE_CLASS
template <typename T>
class dnode
{
public:
// the members of a dnode object are used for operations within a
// doubly linked list; access is simplified by making them public
T nodeValue; // data value of the node
dnode<T> *prev; // previous node in the list
dnode<T> *next; // next node in the list
// default constructor. creates object with value T(), the
// default value of type T. set the node pointers to point at
// the node itself
dnode()
{
next = this; // the next node is the current node
prev = this; // the previous node is the current node
}
// constructor with an argument to initialize nodeValue.
// set the node pointers to point at the node itself
dnode(const T& value): nodeValue(value)
{
next = this; // the next node is the current node
prev = this; // the previous node is the current node
}
};
#endif // DOUBLY_LINKED_NODE_CLASS
#ifndef NODE_CLASS
#define NODE_CLASS
#ifndef NULL
#include <cstddef>
#endif // NULL
// linked list node
template <typename T>
class node
{
public:
T nodeValue; // data held by the node
node<T> *next; // next node in the list
// default constructor with no initial value
node() : next(NULL)
{}
// constructor. initialize nodeValue and next
node(const T& item, node<T> *nextNode = NULL) :
nodeValue(item), next(nextNode)
{}
};
#endif // NODE_CLASS
#ifndef LINKEDLIST_FUNCTIONS
#define LINKEDLIST_FUNCTIONS
#include <iostream>
#include <string>
#include "d_node.h" // use node class
#include "d_dnode.h" // use dnode class
using namespace std;
// output a singly linked list with each element followed by separator
template <typename T>
void writeLinkedList(node<T> *front, const string& separator);
// output a doubly linked list with each element followed by separator
template <typename T>
void writeDLinkedList(dnode<T> *header, const string& separator);
// insert a new node with value item immediately before node curr
template <typename T>
dnode<T> *insert(dnode<T> *curr, const T& item);
// erase dnode pointed to by curr
template <typename T>
void erase(dnode<T> *curr);
// ***********************************************************
// FUNCTION IMPLEMENTATIONS
// ***********************************************************
template <typename T>
void writeLinkedList(node<T> *front, const string& separator = " ")
{
// front points at first node. curr moves through the list
node<T> *curr;
curr = front; // set curr to front of the list
while (curr != NULL) // continue until and of list
{
// output node value and move to the next node
cout << curr->nodeValue << separator;
curr = curr->next;
}
}
template <typename T>
void writeDLinkedList(dnode<T> *header, const string& separator = " ")
{
// header points at first dnode. p moves through the list
dnode<T> *p = header->next ;
while (p != header) // continue until end of list
{
// output dnode value and move to the next dnode
cout << p->nodeValue << separator;
p = p->next;
}
}
template <typename T>
dnode<T> *insert(dnode<T> *curr, const T& item)
{
// declare pointer variables for the new node and the previous node
dnode<T> *newNode, *prevNode;
// allocate new dnode with item as initial value
newNode = new dnode<T>(item);
// assign prevNode the pointer value of node before p
prevNode = curr->prev;
// update pointer fields in newNode
newNode->prev = prevNode;
newNode->next = curr;
// update curr and prevNode to point at newNode
prevNode->next = newNode;
curr->prev = newNode;
return newNode;
}
template <typename T>
void erase(dnode<T> *curr)
{
// return if the list is empty
if (curr->next == curr)
return;
// declare pointers for the predecessor and successor nodes
dnode<T> *prevNode = curr->prev, *succNode = curr->next;
// update pointer fields for predecessor and successor
prevNode->next = succNode;
succNode->prev = prevNode;
// deallocate the memory used by the node
delete curr;
}
#endif // LINKEDLIST_FUNCTIONS
12 9
10.29 55.2 12.4 9.3 62.3 10.26 12.66 12.93 6.63 8.35 12.32 92.97
2.14 12.14 12.9 106.7 8.31 4.24 10.26 10.29 12.14
This attachment is potentially unsafe to open. It may be an executable that is capable of making changes to your file system, or it may require specific software to open. Use caution and only open this attachment if you are comfortable working with msword files.
tux4life 2,072 Postaholic
What do you actually expect from us? We won't do your homework ...
Edit:: But we can still give you some suggestions here and there :) ...
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.