Data structure and algorithms

azrael jura.grozni at gmail.com
Sun Jan 28 18:44:33 EST 2007


i'd like to get more control like in c with pointers. I want to loose 
the data after disabling:

>>> list=[]
>>> list.append(Node(1))
>>> list.append(Node(2))
>>> list[0].next=list[1]


      1, 2


>>> list.append(Node(3))
>>> list[1].next=list[2]


1,2,3


>>> list[0].next=list[2]

1,3                       (but 2 still exists as list[2])



as much simmilar as this:


#include<stdio.h>
#include<stdlib.h>
typedef int element;
struct Lis
	{
		int values[10000];
		int cursor;
	};
typedef struct Lis list;

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))
			{
				printf("Element ne postoji u listi ! \n");
				exit(0);
			}
		else
			return(p+1);
}

element PreviousL(element p, list *Li){
		if ((p>(*Li).cursor) || (p<=0))
			{
				printf("Element ne postoji u listi ! \n");
				exit(0);
			}
		else
			return(p-1);
}


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

void InsertL(int x, element p, list *Li){
		int i;
		if ((p<=(*Li).cursor) && (p>=0)  && ((*Li).cursor<10000))
			{
				for (i=(*Li).cursor; i>=p; i--)
					(*Li).values[i]=(*Li).values[i-1];
				(*Li).cursor++;
				(*Li).values[p]=x;
			}
		else
			{
				if((*Li).cursor>=10000)
					printf("Lista je puna");
				else
				printf("Element ne postoji u listi ! \n");
			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
			{
				printf("Element ne postoji u listi ! \n");
				exit(0);
			}
	}


int RetrieveL(element p, list *Li){
		if ((p<(*Li).cursor) && (p>=0))
			return((*Li).values[p]);
		else
			{
				printf("Element ne postoji u listi ! \n");
				exit(0);
			}
	}



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


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





More information about the Python-list mailing list