🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: es.comp.os.linux.programacion
Article #7833

Ayuda con listas en C.

#7833
From: Cesar
Date: Mon, 13 Jan 2003 05:40
47 lines
1968 bytes
Hola, os agradeceria enormemente que me ayudaseis para decirme si esta
implementacion de listas esta bien, os pongo todo lo necesario del
codigo. A veces me fallan cuando tengo que meter muchos elementos:

/*
Esto son las declaraciones principales, incluyo el campo length en la
lista porque tengo que calcular muchas veces la longitud de la lista y
asi el programa va mucho mas rapido:
*/
typedef unsigned int t_element;

typedef struct node_list_struct *node_list;
struct node_list_struct {
	t_element element;
	struct node_list_struct *next;
};

typedef struct list_struct *t_list;
struct list_struct {
	node_list list;
	int length;
};

/*
Esto es la funcion para a�adir elementos:
*/
void 
list_append(t_list *list, t_element element)
{
	node_list aux1 = NULL, aux2 = NULL;

	aux1 = (node_list) malloc(sizeof(struct node_list_struct));
	aux1->element = element;
	aux1->next = NULL;
	
	if ( *list == NULL) {
		*list = (t_list) malloc(sizeof(struct list_struct));
		(*list)->list = aux1;
		(*list)->length = 1;
	} else {
		aux2 = (*list)->list;
		while (aux2->next != NULL) 
			aux2 = aux2->next;
		aux2->next = aux1;
		(*list)->length++;
	}
}
Technical Details
Message-ID: <9225f930.0301122140.6f5cc93c@posting.google.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!postnews1.google.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: FRENCH,ASCII
X-Google-Thread: f86c8,f8c239b9a1587006,start
X-Google-Attributes: gidf86c8,public
X-Google-ArrivalTime: 2003-01-12 21:40:36 PST
Path: arc1-ca.pugleaf.net!archiver1.google.com!postnews1.google.com!not-for-mail
From: cesarvalgar@hotmail.com (Cesar)
Newsgroups: es.comp.os.linux.programacion
Subject: Ayuda con listas en C.
Date: 12 Jan 2003 21:40:35 -0800
Organization: http://groups.google.com/
Lines: 47
Message-ID: <9225f930.0301122140.6f5cc93c@posting.google.com>
NNTP-Posting-Host: 62.83.52.97
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
X-Trace: posting.google.com 1042436435 8370 127.0.0.1 (13 Jan 2003 05:40:35 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: 13 Jan 2003 05:40:35 GMT