vuoi
o PayPal
tutte le volte che vuoi
T;
typedef int
Coda {
class private: N=5;
static const int
T C[N];
t;
int c;
int elem;
int
public:
Coda();
Push(const T &);
bool Pop(T &);
bool empty()
bool const;
full()
bool const;
print()
void const;
};
#endif
CODA.cpp (ALLOCAZIONE STATICA)
#include "Coda.h"
std;
using namespace
Coda::Coda(){
elem=0;
t=0;
c=0;
} Coda::Push(const T & e) {
bool if(full()) return false;
C[c]=e;
c=(c+1)%N;
elem++;
return true;
} Coda::Pop(T & e){
bool if(empty()) return false;
e=C[t];
t=(t+1)%N;
elem--;
return true;
} Coda::empty() {return elem==0;}
bool const
Coda::full() {return elem==N;}
bool const
Coda::print() {
void const
i=0; i<elem; i++)
for(int
cout<<C[i]<<' ';
}
PILA.h (ALLOCAZIONE STATICA)
#ifndef PILA_H
#define PILA_H
#include <iostream>
std;
using namespace
T;
typedef int
Pila{
class private: N=10;
static const int
T P[N];
t;
int
public:
Pila(): t(0) {}
Push(const T &);
bool Pop(T &);
bool empty()
bool const;
full()
bool const;
Top(T &)
bool const;
};
#endif
PILA.cpp (ALLOCAZIONE STATICA)
#include "Pila.h"
std;
using namespace
Pila::Push(const T & e){
bool
if(full()) return false;
P[t]=e;
t++;
return true;
} Pila::Pop(T & e){
bool if(empty()) return false;
t--;
e=P[t];
return true;
} Pila::Top(T & e)
bool const{
if(empty()) return false;
e=P[t-1];
return true;
} Pila::empty() {t==0;}
bool const
Pila::full() {t==N;}
bool const
CODA.h (ALLOCAZIONE DINAMICA)
#ifndef CODA_H
#define CODA_H
#include <iostream>
std;
using namespace
T;
typedef int
Coda{
class private:
T * C;
t;
int c;
int elem;
int maxelem;
int
public:
Coda(const int=10);
Coda(const Coda &);
Coda & Coda &);
const operator=(const
Push(const T &);
bool Pop(T &);
bool empty()
bool const;
full()
bool const;
print()
void const;
~Coda() {delete [] C;}
};
#endif
CODA.cpp (ALLOCAZIONE DINAMICA)
#include "Coda.h"
std;
using namespace
Coda::Coda(const n){
int
maxelem=n;
C= T [maxelem];
new
elem=0;
t=0;
c=0;
}
Coda::Coda(const Coda & Co){
maxelem=Co.maxelem;
C=new T[maxelem];
t=Co.t;
c=Co.c;
elem=Co.elem;
i=0;i<elem;i++)
for(int C[i]=Co.C[i];
} Coda & Coda::operator =(const Coda & Co){
const if(this!=&Co){ [] C;
if(C) delete
maxelem=Co.maxelem;
C=new T[maxelem];
t=Co.t;
c=Co.c;
elem=Co.elem;
i=0;i<elem;i++)
for(int
C[i]=Co.C[i];
} *this;
return
} Coda::Push(const T & e) {
bool if(full()) return false;
C[c]=e;
c=(c+1)%maxelem;
elem++;
return true;
} Coda::Pop(T & e){
bool if(empty()) return false;
e=C[t];
t=(t+1)%maxelem;
elem--;
return true;
} Coda::empty() {return elem==0;}
bool const
Coda::full() {return elem==maxelem;}
bool const
Coda::print() {
void const
i=0; i<elem; i++)
for(int
cout<<C[i]<<' ';
}
PILA.h (ALLOCAZIONE DINAMICA)
#ifndef PILA_H
#define PILA_H
#include <iostream>
std;
using namespace
T;
typedef int
Pila{
class private:
T * P;
t;
int maxelem;
int
public:
Pila(const int=10);
Pila(const Pila &);
Pila & Pila & );
const operator=(const
Push(const T &);
bool Pop(T &);
bool empty() {return t==0;}
bool const
full() {return t==maxelem;}
bool const
Top(T &)
bool const;
print()
void const;
cancella(const T &);
void int,
~Pila() {if(P) P;}
delete[]
};
#endif
PILA.cpp (ALLOCAZIONE DINAMICA)
#include "PilaAllDin.h"
std;
using namespace
Pila::Pila(const n) {
int
maxelem=n;
P=new T[maxelem];
t=0;
}
Pila::Pila(const Pila & Pi) {
maxelem=Pi.maxelem;
P=new T [maxelem];
t=Pi.t; i=(t-1);i>=0;i--)
for(int
P[i]=Pi.P[i];
} Pila & Pila::operator=(const Pila & Pi) {
const if(this!=&Pi){ [] P;
if(P) delete
maxelem=Pi.maxelem;
P=new T [maxelem];
t=Pi.t; i=(t-1);i>=0;i--)
for(int
P[i]=Pi.P[i];
} *this;
return
} Pila::Push(const T & e) {
bool
if(full()) return false;
P[t]=e;
t++;
return true;
} Pila::Pop(T & e) {
bool if(empty()) return false;
t--;
e=P[t];
return true;
} Pila::cancella(const pos, T & e){
void int
pop(e);
if(t==0)
{
else i=pos;i<t;i++)
for(int
P[i]=P[i+1];
t--;
}