home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.disi.unige.it
/
2015-02-11.ftp.disi.unige.it.tar
/
ftp.disi.unige.it
/
pub
/
.person
/
CataniaB
/
teach-act
/
esempi
/
Comp-Sep
/
list.c
< prev
next >
Wrap
C/C++ Source or Header
|
1997-04-19
|
1KB
|
75 lines
/* List.c: implementazione : */
#include<stdio.h>
#include "list.h"
bool is_empty(dlist *p) { return(p->head->next == p->tail); }
list makecell(void) { return (list) malloc (sizeof (struct cell));}
void init(dlist *p)
{
p->head = makecell();
p->tail = makecell();
p->head->next=p->tail;
}
void first(element *x,element *y,dlist *p)
{
if (!is_empty(p))
{
*x=p->head->next->x;
*y=p->head->next->y;
}
else printf("\n Errore lista vuota");
}
void insert_head(element x,element y,dlist *p)
{
list q;
p->head->x=x;
p->head->y=y;
q = makecell();
q->next=p->head;
p->head=q;
}
void insert_tail(element x,element y,dlist *p)
{
list q;
p->tail->x=x;
p->tail->y=y;
q = makecell();
p->tail->next=q;
p->tail=q;
}
void delete_head(dlist *p)
{
list q;
if (!is_empty(p))
{
q=p->head->next;
p->head->next=q->next;
free(q);
}
else printf("\n Errore stack vuoto");
}
void print(dlist *q)
{
list p;
p=q->head;
printf("\n-");
while (p->next!=q->tail)
{ printf(" (%d,%d)",p->next->x,p->next->y);
p=p->next;
}
printf(" -\n");
}