Lista.h
#ifndef LISTA_H //Compilazione condizionale
#define LISTA_H
#include <iostream>
using namespace std;
struct Record; // Predichiarazione: il nome Record esiste!!!
typedef int T;
struct Record {T chiave;Record * next;};
class Lista {
Record * l;
public:
Lista() {l=0;} // Inizializza la lista
bool Empty() const {return l==0;}
bool Full() const {return false;}
bool Print() const;
bool Append(const T&);
bool Push(const T&);
bool Pop(T&);
bool LastPop(T&);
};
#endif
Lista.cpp
#include "Lista.h"
using namespace std;
//Inserimento in testa
bool Lista::Push(const T & e){if(Full()) return false;Record * temp=new Record;temp->chiave=e;temp->next=l;l=temp;return true;}
//Stampa
bool Lista::Print() const{if(Empty()) return false;Record * temp=l;while(temp){cout<<temp->chiave;temp=temp->next;}return true;}
//Inserimento in coda
bool Lista::Append(const T & e){if(Full()) return false;Record * temp=new Record;Record * p=l;temp->chiave=e;temp->next=0;while(p->next) p=p->next;p->next=temp;return true;}
//Eliminazione in testa
bool Lista::Pop(T & e){if(Empty()) return false;Record * temp=l;e=l->chiave;l=l->next;delete temp;return true;}
//Eliminazione in coda
bool Lista::LastPop(T & e){if(Empty()) return false;Record * temp;Record * p=l;while(p->next->next) p=p->next;e=p->next->chiave;temp=p->next;p->next=0;delete temp;return true;}
Coda.h (Allocazione statica)
#ifndef CODA_H
#define CODA_H
#include <iostream>
std;
using namespaceT;
typedef intCoda {class private: N=5;static const intT 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
-
Informatica I - tipi di dati astratti e strutture di dati
-
Strutture Dati
-
Algoritmi e Strutture dati
-
Algoritmi e strutture dati