please help

Please write a class of a stack that holds int type values and keeps a LinkedList
as its main structure. Please help
Last edited on
1
2
3
4
#include <stack>
#include <list>

std::stack<int, std::list<int>> MyClass;
Do you pour the code stack and LinkedList? please help
Last edited on
This is the standard libraries and standard containers. This code works already.
http://en.cppreference.com/w/cpp/container/stack
Not like you wrote
1-)The main structure of linked lists to be created;
2-)created a stack class with int value;
3-)values ​​are displayed after printing;
library will not be used
If you going to reivent the wheel, at least show your attempts.

Please note, that it is not a homework site. We won't do your homework for you. However we are always willing to help solve problems you encountered, correct mistakes you made in your code and answer your questions.

We didn't see your attemts to solve this youself and so we cannot correct mistakes you didn't made and answer questions you didn't ask. To get help you should do something yourself and get real problems with something. If your problem is "I don't understand a thing", then you should go back to basics and study again. As it is impossible to find deriviative of function without knowledge in ariphmetics, you cannot do more complex tasks in programming without clear understanding of basics
I'm having trouble just writing prototypes
If you can help my homework
okay
here is prototypes:
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
struct Node
{
    int data;
    Node* next;
    Node* previous;
}

class LinkedList
{
private:
    Node* begin;
    Node* end;
public:
    int get_value(int index)
    void push_back(int data);
    void insert(int data, int index);
    void delete(int index);
    int size();
    LinkedList();
}

class Stack
{
private:
    LinkedList container;
public:
    void push(int);
    int pop();
    Stack();
}
thank you very much
Try this, I think it works


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
90
91



#include <iostream>

using namespace std;


struct Element{

	int number;
	Element *next;

};

class Stack{

public:

	Stack(){first=NULL;}
	~Stack(){
		int number;
		while(!is_empty())
			number=pop();
	}

	void push(const int the_number){
		
		Element *temp=new Element;
		temp->number=the_number;

		temp->next=first;
		first=temp;
	
	}
	int pop(){
		
		if(is_empty())
			exit(1);

		Element *temp=first;

		int result=temp->number;

		first=temp->next;

		delete temp;

		return result;
		
	}
	bool is_empty(){
	
		if(first==NULL)
			return true;
		return false;
	
	}

private:

	Element *first;

};

int main(){

	char hold;

	Stack stack;
	int popped;

	stack.push(43);
	stack.push(2);
	stack.push(8);
	stack.push(4);
	stack.push(9);

	popped=stack.pop();
	cout<<"Popped: "<<popped<<endl;

	popped=stack.pop();
	cout<<"Popped: "<<popped<<endl;

	popped=stack.pop();
	cout<<"Popped: "<<popped<<endl;

	cin>>hold;
	return 0;
}
Topic archived. No new replies allowed.