Plz Correct it for me and Comment where correction was required.

Write your question here.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
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;
    friend class 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"
using namespace 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"

using namespace std;

int main()
{
    DLinkedList s;
    s.insertatHeader (2);  // here when i type "s." i dont see memberfuntions of DLinkedList
    return 0;
}
Last edited on
closed account (L6b7X9L8)
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.
i am beginner ,this site doenst help begginers?
i am beginner ,this site doenst help begginers?


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.
Line 54: Your destructor is a declaration, not an implementation. i.e. it needs a body {}

As Zorg pointed out, your destructor is responsible for deallocating all the memory you allocated via new.

Line 64: Capitalization error.

Lines 71-73: These functions need bodies.

Topic archived. No new replies allowed.