Stacked Linked List question

Ok here is my code so far. I am trying to create a function to pop or append a value to the top/head of the stack.
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
#include <iostream>
using namespace std;

class node {
    void *info;
    node *next;
public:
    node (void *v) {info = v; next = 0; }
    void put_next (node *n) {next = n;}
    node *get_next ( ) {return next;}
    void *get_info ( ) {return info;}
};

class list {
    node *head;
    int node_num;
public:
    list ( ) { node_num = 0; head = 0;}
    void remove (int);
    void insert (void *, int);
    void append (void * v) {insert (v, node_num + 1); }
    void *find (int);
    void display ( );
};

class stack
{
    list stacklist;
    node *head;
    
    public:
    stack() // constructor
    {
        head=NULL;
    }
    void push(); // to insert an element
    void pop();  // to delete an element
    void show(); // to show the stack
};

void append()
{
	node *ptr;
    int value;
    cout<<"\nPUSH Function\n";
    cout<<"Enter a number to insert: ";
    cin>>value; 
    if(head!=NULL)
        ptr->next;
    head=ptr;
    cout<<"\nNumber has been inserted into the stack.";
 
}


When I compile I get the following errors:


In function 'void append()':
48:8: error: 'head' was not declared in this scope
6:11: error: 'node* node::next' is private
49:14: error: within this context
49:18: warning: statement has no effect [-Wunused-value]
50:5: error: 'head' was not declared in this scope


Can someone point (pun intended) me in the right direction?
Last edited on
What does it do that you don't think it should do, or what does it not do that you want it to do?

If it doesn't compile, what's the first error? Always start with the first error.
Last edited on
Topic archived. No new replies allowed.