Escolar Documentos
Profissional Documentos
Cultura Documentos
Arquivo listaarranjo.h:
#ifndef LISTAARRANJO_H
#define LISTAARRANJO_H
class ListaArranjo{
public:
typedef struct nItem{ char *s; };
nItem *item;
ListaArranjo(int tamMax);
#endif
Arquivo listaarranjo.cpp (obs: stdafx.h é um arq. de conf. padrão no softw. VC++):
#include "stdafx.h"
#include "listaarranjo.h"
int i;
for (i = 0; i < tamMax; i++){
(this->item+i)->s = (char *)malloc(sizeof(char)*3); // * 3 ???
}
}
return NULL;
}
//this->ultimo = this->ultimo-1;
this->ultimo--;
int aux;
char *item = (this->item+p)->s;
for (aux = p; aux < this->ultimo; aux++) { //"empurra" para frente
(this->item+aux)->s = (this->item+(aux + 1))->s;
}
return item;
}
char * ListaArranjo::retiraPrimeiro(){
if (this->vazia()) { return NULL; }
char *item = (this->item+0)->s;
//this->ultimo = this->ultimo − 1;
this->ultimo--;
int aux;
for (aux = 0; aux < this->ultimo; aux++) { //"empurra" para frente
(this->item+aux)->s = (this->item+(aux + 1))->s;
}
return item;
}
char * ListaArranjo::getPrimeiro(){
if (this->vazia()) { return NULL; }
return (this->item+this->primeiro)->s;
}
bool ListaArranjo::vazia ( ) {
return (this->primeiro == this->ultimo);
}
#include "stdafx.h"
#include "listaarranjo.h"
listaA.insere("Novo item");
listaA.insere("Novo item 2");
listaA.insere("Novo item 3");