Pointer

What is the problem with this code?It Doesnt show my display ??

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
88
89
 #include<iostream>
#include<string>

using namespace std;

class store{

    int id;
    float cgpa;
    string name;
    public:
    void input(){
        cin.ignore();
        cout<<"Enter Name ";
        getline(cin,name);
        cout<<"Enter Id ";
        cin>>id;
        cout<<"Enter CGPA ";
        cin>>cgpa;
    }

    void display(){
        cout<<name;
        cout<<id;
        cout<<cgpa;
    }
};

class Node{
    store data;
    Node *next;

    public:

    void insert(Node *&h , Node *&t){

        if(h==NULL){
            h=new Node;
            h->data.input();
            h->next=NULL;
            t=h;
        }

        else{
            t->next=new Node;
            t=t->next;
            t->data.input();
            t->next=NULL;
        }
    }

     void Display(Node*& h)
    {
        if(h==NULL) cout<<"The list is empty!!!"<<endl;
        else{
            Node* current = h;
            while(current != NULL) {
                data.display();
                current = current->next;
                cout<<endl;
            }

        }
    }
};

int main(){
    Node p;
    Node *Head, *tail;
    Head=tail=NULL;
    int c;

    do{  cout<<"Enter choice "<<endl;
        cout<<"Enter [1] to create a node at the end of the list."<<endl;
        cout<<"Enter [2 display the Node"<<endl;
        cin>>c;

    switch(c){
        case 1:
            p.insert(Head,tail);break;
        case 2:
            p.Display(Head);break;
    }
    }
    while(c!=3);


}
data.display();

This is showing the data from p, which is never assigned to. You want

current->data.display();
Txxxx jamess
Topic archived. No new replies allowed.