# Posted By

dfilipov on 11/12/12

# Statistics

Viewed 186 times
Favorited by 0 user(s)

# SP Zadatak 1 - implementacija pomocu pokazivaca

/ Published in: C++
`struct s_datum {	unsigned int dan;	unsigned int mjesec;	unsigned int godina;}; struct s_zapis {	short sifra;	char vrsta[50];	char naziv[50];	float cijena;	s_datum datum;}; struct lista {	s_zapis zapis;	lista *NEXT;};typedef lista *element;  element EndL(lista *L) {	lista *LAST = L;	while (LAST->NEXT)		LAST = LAST->NEXT; 	return LAST;} element FirstL(lista *L) {	if (L->NEXT)		return L;	else		return EndL(L);} element NextL(element p, lista *L) {	if (p->NEXT)		return p->NEXT;	else		return EndL(L);} element PreviousL(element p, lista *L) {	if (p==L) return 0;	lista *prev = L;	while (prev->NEXT) {		if (prev->NEXT == p)			return prev;		prev = prev->NEXT;	}	return FirstL(L);} element LocateL(s_zapis X, lista *L) {	lista *flow = L->NEXT;	while (flow) {		if (!strcmp(flow->zapis.vrsta, X.vrsta))			return flow;		else if (!strcmp(flow->zapis.naziv, X.naziv))			return flow; 		flow = flow->NEXT;	} 	return EndL(L);} bool InsertL(s_zapis X, element p, lista *L) {	if (L) {		element novi = new lista;		novi->zapis = X;		novi->NEXT = p->NEXT;		p->NEXT = novi;		return true;	}	else		return false;} bool DeleteL(element p, lista *L) {	element prev, flow;	flow = p;	if (p == FirstL(L)) {		L->NEXT = flow->NEXT;		delete flow;		return true;	}	else if (p != FirstL(L)){		prev = PreviousL(flow, L);		prev->NEXT = flow->NEXT;		delete flow;		return true;	}	else return false;} s_zapis RetrieveL(element p, lista *L) {	return p->zapis;} lista *InitL(lista *L) {	L = new lista;	L->NEXT = NULL;	return L;}`