-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlisting44.cpp
84 lines (72 loc) · 1.49 KB
/
listing44.cpp
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
//cola definica en un arreglo
//incluye constructores y destructores a
#include <iostream>
#include <string.h>
#include <stdio.h>
using namespace std;
class Cola{
private:
int q[10], sloc, rloc;
char *nom;
public:
Cola (const char *cad=NULL)//Funcion en linea//Contructor
{
if (cad)
{
nom = new char[strlen(cad)+1];
strcpy(nom, cad);
}else{
nom = NULL;
}
sloc = rloc = -1;
}
~Cola( ){//Destructor de la cola
if (nom)//nom!=NULL
{
cout << "Cola:"<<nom<<"destruida\n";
delete [] nom;
}
}
char set(int);
int get();
};
char Cola::set(int val)
{
if (sloc>=10)
{
cout << "LA cola esta llena";
return 0; //
}
sloc++;
q[sloc] = val;
return 1;
}
int Cola::get()
{
if (rloc==sloc)
{
cout << "La cola esta vacia";
}else{
rloc++;
return q[rloc];
}
return 0;
}
int main()
{
Cola a("Cola a "), b("Cola b "),
*pCola = new Cola ("Cola dinamica pCola ");
a.set(1);
b.set(2);
pCola ->set(3);
a.set(11);
b.set(22);
pCola->set(33);
cout <<a.get() <<endl;
cout <<a.get() <<endl;
cout <<b.get() <<endl;
cout <<b.get() <<endl;
cout <<pCola->get() <<endl;
cout <<pCola->get() <<endl;
delete pCola;
}