In: Computer Science
I create a h file, and I wrote
#ifndef MYSTACK_H
#define MYSTACK_H
#include <cstdlib>
#include <cstddef>
#include <iostream>
struct node
{
int value;
node* next;
node(int value, node* next = nullptr)
{
this->value = value;
this->next = next;
}
};
class mystack
{
private:
node* stack_top;
size_t stack_size;
public:
mystack();
mystack(const mystack& x);
~mystack();
mystack& operator=(const mystack& x);
size_t size() const;
bool empty() const;
void clear();
const int& top() const;
void push(int value);
void pop();
void clone(const mystack& x);
};
#endif
how do I write a default constructer for my node structure?
C++
Code
#ifndef MYSTACK_H
#define MYSTACK_H
#include <cstdlib>
#include <cstddef>
#include <iostream>
struct node
{
int value;
node* next;
node()//this is your default constructor
{
this->value = 0;
this->next = nullptr;
}
node(int value, node* next = nullptr)
{
this->value = value;
this->next = next;
}
};
class mystack
{
private:
node * stack_top;
size_t stack_size;
public:
mystack();
mystack(const mystack& x);
~mystack();
mystack& operator=(const mystack& x);
size_t size() const;
bool empty() const;
void clear();
const int& top() const;
void push(int value);
void pop();
void clone(const mystack& x);
};
#endif
If you have any query regarding the code please ask me in the comment i am here for help you. Please do not direct thumbs down just ask if you have any query. And if you like my work then please appreciates with up vote. Thank You.