Return to Snippet

Revision: 60491
at November 10, 2012 21:54 by hackerma3x


Initial Code
#ifndef LISTA_POK_H
#define LISTA_POK_H

#include <iostream>
#include <cstring> // memcpy()
using namespace std;

#define ERROR_CODE NULL

struct tDatum {
	short dan, mjesec, godina;
};

struct tZiv {
	int sifra;
	char vrsta[50], naziv[50];
	float cijena;
	tDatum dat_dostave;
};
struct tEl {
	tZiv el;
	tEl* slj;
};

typedef tEl Lista;
typedef tEl* Element;

typedef tZiv Zivotinja;
typedef tDatum Datum;

bool operator==(Datum d1, Datum d2) {
	if(d1.dan != d2.dan) return false;
	if(d1.mjesec != d2.mjesec) return false;
	if(d1.godina != d2.godina) return false; 
	return true;
}

bool operator==(Zivotinja z1, Zivotinja z2) {
	if(z1.sifra != z2.sifra) return false;
	if(z1.cijena != z2.cijena) return false;
	if(z1.sifra != z2.sifra) return false;
	if(z1.sifra != z2.sifra) return false;
	if(!(z1.dat_dostave == z2.dat_dostave) ) return false;
	return true;
};

ostream& operator<<(ostream& os, Datum d1) {
	os << d1.dan << '.' << d1.mjesec << '.' << d1.godina << '.';
	return os;
}

ostream& operator<<(ostream& os, Zivotinja z1) {
	os << "Sifra: " << z1.sifra << endl;
	os << "Naziv: " << z1.naziv << endl;
	os << "Vrsta: " << z1.vrsta << endl;
	os << "Cijena: " << z1.cijena << endl;
	os << "Datum dostave: " << z1.dat_dostave << endl;
	return os;
}

// proto func
Element FirstL(Lista*);
Element EndL(Lista*);

Element NextL(Element, Lista*);
Element PreviousL(Element, Lista*);

Element LocateL(Zivotinja, Lista*);
bool InsertL(Zivotinja, Element, Lista*);

bool DeleteL(Element, Lista*);
Zivotinja RetrieveL(Element, Lista*);

void DeleteAllL(Lista*);
void InitL(Lista*);

// func
Element FirstL(Lista* L) {
	return L;
}

Element EndL(Lista* L) {
	Element tren = L;
	while(tren->slj) tren=tren->slj;
	return tren;
}

Element NextL(Element p, Lista* L) {
	if(p->slj) return p->slj;
	return ERROR_CODE;
}

Element PreviousL(Element p, Lista* L) {
	if(p==FirstL(L) ) return ERROR_CODE;
	Element tren=FirstL(L);
	while(tren->slj!=p) tren=tren->slj;
	return tren;
}

Element LocateL(Zivotinja x, Lista* L) {
	for(Element tren=L; tren->slj; tren=tren->slj)
		if(tren->slj->el == x) return tren;
	return EndL(L);
}

bool InsertL(Zivotinja x, Element p, Lista* L) { // ***
	if(!L) return 0;
	Element novi = new tEl;
	memcpy(novi, &x, sizeof(Zivotinja) );
	novi->slj = p->slj;
	p->slj = novi;
	return 1;
}

bool DeleteL(Element p, Lista* L) {
	if(!L) return 0;
	Element tren = p->slj;
	p->slj = tren->slj;
	delete tren;
	return 1;
}
Zivotinja RetrieveL(Element p, Lista* L) {
	return p->slj->el;
}

void DeleteAllL(Lista* L) {
	if(!L) return;
	if(!L->slj) return;
	Element prev = L->slj;
	for(Element tren=prev->slj; tren!=NULL; tren=(prev=tren)->slj)
		delete prev;
	delete prev;
	L->slj = NULL;
}
void InitL(Lista* L) {
	L->slj = NULL;
}

#endif // LISTA_POK_H

// hackerma3x (2012)

Initial URL


Initial Description
Datoteka zaglavalja
lista pokazivaci

Initial Title
SP - Zadatak 1 - ATP Liste - Lista pokazivaci

Initial Tags


Initial Language
C++