Doubly Linked list with head node

Hello i am trying to develop a doubly linked list class. I became stuck at a few of the functions as well as the main.cpp file. i have to insert a character sentence "TRICK OR TREAT" spaces included. I am stuck on the display and the listsize functions and im unsure if my insert has the head node in it.
The function parameters were given to us and most of this code was given from a single linked list. Any advice would be very helpful.

//node.h
#pragma once
class Node
{
public:
char data;
Node *next;
Node(char d);
};

//node.cpp
#pragma once

#include <iostream>
using namespace std;
#include "node.h"

Node::Node(char d)
{
data = d;
next = '\0';//null
}

//DList.h
#pragma once
#include "node.h"
class DList
{
public:
Node * first; // first pointer
DList(); // constructor
bool empty(); // empty checker
void insert(Node *newnode, Node *pred); // new node after the predecessor
void erase(Node *dnode); // delete node from list
void display(); // to display each item on the list from the beginning to the end
int listSize(); // return the size of the list must perform O(1) time
};

//DList.cpp
#include<iostream>
using namespace std;
#include "node.h"
#include "DList.h"
DList::DList()
{
first = '\0'; // when list first made give first element ptr as null
}

bool DList::empty() //O(1) check if list empty
{
if (first == '\0')
return true;

else
return false;
}


void DList::insert(Node*newnode, Node *pred) // to insert at a certain node, ptr
{
newnode->next = pred->next; //previous node name and ptr name moved to next element
pred->next = newnode;
}

void DList::erase(Node *dnode )// since do not know where predecessor is must erase element by moving to next node
{
Node *temp; // do this by creating a temporary node to remember the current nodes data
temp = dnode->next;
dnode->next = dnode->next->next;
temp->next = '\0'; // set current node = to null
}

void DList::display()
{

}

int DList::listSize()
{

}

//sequence for main
//DLinked.cpp main

// instantiate all necessary nodes to do the project

// instantiate list object

// insert "TRICK OR TREAT" to the list by char data spaces are also nodes

// display list

// display size of list

// erase "OR" from the list

// display the list

// display the size of the list

closed account (jivRfSEw)
Hello fellow ECE 304 classmate,

I see that you are trying to receive some "help". Certainly, it would be bad if the professor sees this post if you know what I mean *cough cough cough* I hope you have a wonderful Trick or Treat!

- Yours truly,
The Justice Seeker

PS - Just add missing components to the single linked list example given in class and you should be alright assuming you are able to make the necessary minor adjustments.

See you in class on Tuesday!!!
Topic archived. No new replies allowed.