Luc@s
26-05-2004, 11:16
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include <malloc.h>
struct List
{
int el;
struct List *next;
struct List *prev;
};
void init(struct List *aux, int el);
void add(struct List *aux, int el);
void init(struct List *aux, int el)
{
assert(aux != NULL);
aux->el = el;
aux->next = NULL;
aux->prev = NULL;
}
void add(struct List *aux, int el)
{
assert(aux != NULL);
while(aux->next != NULL)
aux = aux->next;
struct List *tmp = (struct List *)malloc(sizeof(struct List));
tmp->el = el;
tmp->prev = aux;
tmp->next = NULL;
aux->next = tmp;
}
int main(int argc, char *argv[])
{
struct List *head = (struct List *)malloc (sizeof(struct List));
init(head, 10);
add(head, 9);
add(head, 8);
while(head->prev != NULL)
{
printf("%d\n", head->el);
head = head->prev;
}
char c;
scanf("%s", &c);
return 0;
}
Perche nn mi visualizza nulla anche se nn mi da errore???
Tnk
#include <string.h>
#include <assert.h>
#include <malloc.h>
struct List
{
int el;
struct List *next;
struct List *prev;
};
void init(struct List *aux, int el);
void add(struct List *aux, int el);
void init(struct List *aux, int el)
{
assert(aux != NULL);
aux->el = el;
aux->next = NULL;
aux->prev = NULL;
}
void add(struct List *aux, int el)
{
assert(aux != NULL);
while(aux->next != NULL)
aux = aux->next;
struct List *tmp = (struct List *)malloc(sizeof(struct List));
tmp->el = el;
tmp->prev = aux;
tmp->next = NULL;
aux->next = tmp;
}
int main(int argc, char *argv[])
{
struct List *head = (struct List *)malloc (sizeof(struct List));
init(head, 10);
add(head, 9);
add(head, 8);
while(head->prev != NULL)
{
printf("%d\n", head->el);
head = head->prev;
}
char c;
scanf("%s", &c);
return 0;
}
Perche nn mi visualizza nulla anche se nn mi da errore???
Tnk