File tree 1 file changed +167
-0
lines changed
1 file changed +167
-0
lines changed Original file line number Diff line number Diff line change
1
+
2
+ #include < iostream>
3
+ #include < queue>
4
+ #include < stack>
5
+
6
+ using namespace std ;
7
+
8
+ class persona {
9
+ private:
10
+ string name;
11
+ string profesion;
12
+ int edad;
13
+
14
+ public: // constructor
15
+ persona (string name,string profesion,int edad){
16
+ this ->name = name;
17
+ this ->profesion = profesion;
18
+ this ->edad = edad;
19
+ }
20
+
21
+ void imprimir (){
22
+ cout<<" Nombre: " <<this ->name <<endl<<" Edad: " <<this ->edad <<endl<<" Profesion: " <<this ->profesion <<endl;
23
+ }
24
+ };
25
+
26
+ class Pila {
27
+ private:
28
+ stack<int >pp;
29
+
30
+ public:
31
+ Pila (){
32
+
33
+ }
34
+
35
+ void agregarDato (int dato){
36
+ pp.push (dato);
37
+ cout<<" El número ingresado a la Pila: " <<dato<<endl;
38
+ }
39
+
40
+ void eliminarDato (){
41
+ pp.pop ();
42
+ cout<<" Se elimina un número de la Pila" <<endl;
43
+ }
44
+
45
+ void primerStack (){
46
+ cout<<" Primer elemento de la Pila: " <<pp.top ()<<endl;
47
+ }
48
+
49
+ void tamañoStack(){
50
+ cout<<" Tamaño de la Pila: " <<pp.size ()<<endl;
51
+ }
52
+
53
+ void totalStack (){
54
+ stack<int > tmp=pp;
55
+ int i = 1 ;
56
+ cout<<" Elementos en Pila:" <<endl;
57
+ while (i!=tmp.size ()){
58
+ i++;
59
+ if (!tmp.empty ()){
60
+ cout<<tmp.top ()<<endl;
61
+ tmp.pop ();
62
+ }
63
+ else {
64
+ break ;
65
+ }
66
+ }
67
+ }
68
+ };
69
+
70
+ class Cola {
71
+ private:
72
+ queue<int >qq;
73
+ int numero;
74
+
75
+ public:
76
+ Cola (){
77
+ this ->numero ;
78
+ }
79
+
80
+
81
+ void agregarDato (int dato){
82
+ this ->numero = dato;
83
+ qq.push (this ->numero );
84
+ cout<<" El número ingresado al Queue: " <<this ->numero <<endl;
85
+ }
86
+
87
+ void eliminarDato (){
88
+ qq.pop ();
89
+ cout<<" Se elimina un número del Queue" <<endl;
90
+ }
91
+
92
+ void mostrarQueue (){
93
+ cout<<" Primer elemento del Queue: " <<qq.front ()<<endl;
94
+ }
95
+
96
+ void tamañoQueue(){
97
+ cout<<" Tamaño del Queue: " <<qq.size ()<<endl;
98
+ }
99
+
100
+ void ultimoQueue (){
101
+ cout<<" Ultimo elemento: " <<qq.back ()<<endl;
102
+ }
103
+
104
+ void totalQueue (){
105
+ queue<int > tmp=qq;
106
+ int i = 1 ;
107
+ cout<<" Elementos en Queue:" <<endl;
108
+ while (i!=tmp.size ()){
109
+ i++;
110
+ if (!tmp.empty ()){
111
+ cout<<tmp.front ()<<endl;
112
+ tmp.pop ();
113
+ }
114
+ else {
115
+ break ;
116
+ }
117
+ }
118
+ }
119
+ };
120
+
121
+ int main ()
122
+ {
123
+ persona* gente1 = new persona (" María" ," Doctora" ,19 );
124
+ gente1->imprimir ();
125
+
126
+ cout<<endl;
127
+
128
+ persona* gente2 = new persona (" Jóse" ," Profesor" ,30 );
129
+ gente2->imprimir ();
130
+
131
+ // Dificultad extra
132
+ Cola par;
133
+ Pila par2;
134
+
135
+ cout<<endl<<" ------------------------Queue------------------------" <<endl;
136
+
137
+ par.agregarDato (30 );
138
+ par.agregarDato (7 );
139
+ par.agregarDato (11 );
140
+ par.agregarDato (5 );
141
+
142
+ cout<<endl;
143
+ par.mostrarQueue ();
144
+ par.totalQueue ();
145
+ par.ultimoQueue ();
146
+ par.tama ñoQueue ();
147
+ par.eliminarDato ();
148
+ par.mostrarQueue ();
149
+ par.tama ñoQueue ();
150
+
151
+ cout<<endl<<" -----------------------Stack-----------------------" <<endl;
152
+
153
+ par2.agregarDato (10 );
154
+ par2.agregarDato (3 );
155
+ par2.agregarDato (9 );
156
+ par2.agregarDato (17 );
157
+
158
+ cout<<endl;
159
+ par2.tama ñoStack ();
160
+ par2.totalStack ();
161
+ par2.primerStack ();
162
+ par2.eliminarDato ();
163
+ par2.tama ñoStack ();
164
+ par2.primerStack ();
165
+
166
+ return 0 ;
167
+ }
You can’t perform that action at this time.
0 commit comments