Its Doubly Linked List ,i have wriiten the code for insertion at head and trailer ,but when i created object in main ,i got lots of errors Kindly correct it for me ,and write the implementaions of others funtions too i-e removal at head and trailer.my email id is javednoman19@yahoo.com or nomanjaved19@gmail.com i use CodeBlocks IDE latest Version
// Header File Text
#ifndef DLINKEDLIST_H_INCLUDED
#define DLINKEDLIST_H_INCLUDED
class Node
{
public:
Node (int);
~Node ();
private:
int data;
Node* next;
Node* previous;
friendclass DLinkedList;
};
class DLinkedList
{
public:
DLinkedList ();
~DLinkedList ();
void insertatHeader (int);
void insertatTrailer (int);
void removeatHeader ();
void removeatTrailer ();
void Traverse ();
private:
Node* header ;
Node* trailer;
};
#endif // DLINKEDLIST_H_INCLUDED
//.cpp Source file
#include <iostream>
#include "DLinkedList.h"
usingnamespace std;
Node::Node (int d)
{
data = d;
next = NULL;
previous = NULL;
};
DLinkedList::DLinkedList ()
{
header = new Node (0);
trailer = new Node(0);
header->next=trailer;
trailer->previous = header;
header->previous=NULL;
trailer->next = NULL;
};
DLinkedList::~DLinkedList ();
void DLinkedList:: insertatHeader (int d)
{
Node* n = new Node (d);
n->next =header->next;
header->next=n;
n->previous=n->next->previous;
n->next->previous=n;
};
void DLinkedList:: insertatTrailer (int d)
{ Node* n =new node (d);
n->previous=trailer->previous;
trailer->previous=n;
n->next = n->previous->next;
n->previous->next=n;
};
void DLinkedList:: removeatHeader ();
void DLinkedList:: removeatTrailer ();
void DLinkedList:: Traverse ();
//Main
#include <iostream>
#include "DLinkedList.h"
usingnamespace std;
int main()
{
DLinkedList s;
s.insertatHeader (2); // here when i type "s." i dont see memberfuntions of DLinkedList
return 0;
}
When debugging a program, start from the first error and work your way down. People won't do your work for you. The point of being a programmer is solving programs.
Hint: If using new you must free your memory with delete after it has been used. That's all I can see at a glance.
We certainly do help beginners, but we don't do their work for them. Nor do we email solutions to them rather than work it out on the forums where other beginners may benefit from seeing it and where you may be more sure of getting accurate information by dint of exposure to more people.