Return to Snippet

Revision: 39145
at January 14, 2011 01:50 by sejstefic


Initial Code
typedef int element;

struct list {
	elementtype values[100001];
	int cursor;
};


int FirstL(list *Li)
{
	return(0);
}

int EndL(list *Li)
{
	return(Li->cursor);
}


element NextL(element p, list *Li)
{
	if ((p>=Li->cursor) || (p<0)) {
		cout << "Nepostojeci element listeNEXT";
		system("pause");
		exit(0);
	}
	else
		return(p+1);
}


element PreviousL(element p, list *Li)
{
	if ((p>Li->cursor) || (p<=0)) {
		cout << "Nepostojeci element listePREV";
		system("pause");
        exit(0);
	}
	else
		return(p-1);
}


element LocateL(elementtype x, list *Li)
{
	int i;
	i=0;
	while ((i!= Li->cursor) && (Li->values[i]!=x)) i++;
	return(i);
}


void InsertL(elementtype x, element p, list *Li)
{
	int i;
	if ((p<=Li->cursor) && (p>=0)  && (Li->cursor<100005)) {
		for (i=Li->cursor; i>=p; i--)
			Li->values[i]=Li->values[i-1];
		Li->cursor++;
		Li->values[p]=x;
	}
	else {
		if(Li->cursor>=100005)
			cout << "Lista je puna";
		else
			cout << "Nepostojeci element listeINSERT";
			system("pause");
		exit(0);
	}
}


void DeleteL(element p, list *Li)
{
	int i;
	if ((p<Li->cursor) && (p>=0)) {
		for (i=p; i<Li->cursor; i++)
			Li->values[i]=Li->values[i+1];
		(*Li).cursor--;
	}
	else {
		cout << "Nepostojeci element listeDEL";
		system("pause");
		exit(0);
	}
}


elementtype RetrieveL(element p, list *Li)
{
	if ((p<Li->cursor) && (p>=0)) {
		return(Li->values[p]);
	}
	else {
		cout << "Nepostojeci element listeRETRIVER";
		system("pause");
		exit(0);
	}
}


void DeleteAllL(list *Li)
{
	Li->cursor=0;
}


void InitL(list *Li)
{
	Li->cursor=0;
}

Initial URL

                                

Initial Description

                                

Initial Title
Implementacija liste pomocu pokazivaca

Initial Tags

                                

Initial Language
C++