Estratto del documento

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 namespace

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<

Anteprima
Vedrai una selezione di 4 pagine su 15
Strutture Dati Astratti: Contenitori Pag. 1 Strutture Dati Astratti: Contenitori Pag. 2
Anteprima di 4 pagg. su 15.
Scarica il documento per vederlo tutto.
Strutture Dati Astratti: Contenitori Pag. 6
Anteprima di 4 pagg. su 15.
Scarica il documento per vederlo tutto.
Strutture Dati Astratti: Contenitori Pag. 11
1 su 15
D/illustrazione/soddisfatti o rimborsati
Acquista con carta o PayPal
Scarica i documenti tutte le volte che vuoi
Dettagli
SSD
Scienze matematiche e informatiche INF/01 Informatica

I contenuti di questa pagina costituiscono rielaborazioni personali del Publisher cikenthebest di informazioni apprese con la frequenza delle lezioni di Programmazione 1 e studio autonomo di eventuali libri di riferimento in preparazione dell'esame finale o della tesi. Non devono intendersi come materiale ufficiale dell'università Università degli studi di Napoli Federico II o del prof Vittorini Valeria.
Appunti correlati Invia appunti e guadagna

Domande e risposte

Hai bisogno di aiuto?
Chiedi alla community