Return to Snippet

Revision: 60490
at November 10, 2012 21:52 by hackerma3x


Initial Code
#ifndef LISTA_POLJE_H
#define LISTA_POLJE_H

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

#define MAKSIMALNI_BROJ_ELEMENATA_LISTE 5000
#define ERROR_CODE -1

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

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

struct tLista {
	tZiv el[MAKSIMALNI_BROJ_ELEMENATA_LISTE];
	int kursor;
};

typedef tLista Lista;
typedef int 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 0;
}
Element EndL(Lista* L) {
	return L->kursor;
}

Element NextL(Element p, Lista* L) {
	if(p==EndL(L) ) return ERROR_CODE;
	return p+1;
}
Element PreviousL(Element p, Lista* L) {
	if(p==FirstL(L) ) return ERROR_CODE;
	return p-1;
}

Element LocateL(Zivotinja x, Lista* L) {
	for(int i=0; i<L->kursor; i++)
		if(L->el[i] == x) return i;
	return EndL(L);
}
bool InsertL(Zivotinja x, Element p, Lista* L) {
	if(p<0 || p>L->kursor) return 0;
	if(L->kursor >= MAKSIMALNI_BROJ_ELEMENATA_LISTE) return 0;
	for(int i=L->kursor++; i>p; i--)
		L->el[i] = L->el[i-1];
	L->el[p] = x;
	return 1;
}

bool DeleteL(Element p, Lista* L) {
	if(p<0 || p>L->kursor) return 0;
	for(int i=p+1; i<L->kursor; i++)
		L->el[i-1] = L->el[i];
	L->kursor--;
	return 1;
}
Zivotinja RetrieveL(Element p, Lista* L) {
	return L->el[p];
}

void DeleteAllL(Lista* L) {
	L->kursor = 0;
}
void InitL(Lista* L) {
	L->kursor = 0;
}

#endif // LISTA_POLJE_H

// hackerma3x (2012)

Initial URL


Initial Description
Datoteka zaglavlja
lista kao polje

Initial Title
SP - Zadatak 1 - ATP Liste - Lista kao polje

Initial Tags


Initial Language
C++