Funzioni Fondamenti Informatica (S. Cavalieri): EnQueue

Page 1

INSERIMENTO CODA void EnQueue(queue *q, tipobaseQueue x){ struct nodoQueue *temp; temp = (struct nodoQueue *)malloc(sizeof(struct nodoQueue)); temp->info = x; temp->next = CODAVUOTA; if(EmptyQueue(*q)) q->front = q->rear = temp; else{ q->rear->next = temp; q->rear = temp; } }

HH00

q

x NULL

temp

INSERIMENTO CODA GENERICA IN POSIZIONE REAR CD00

FF00

AB00

rear front QUANDO LA CODA E’ VUOTA PER DEFINIZIONE SI HA:

q CD00

AB00

NULL HH00

HH00

x NULL

temp rear

INSERIMENTO CODA VUOTA

front

rear

boolean EmptyQueue(queue q){ return (q.front == CODAVUOTA && q.rear = CODAVUOTA); } ED E’ QUINDI NECESSARIO FAR AVANZARE I DUE PUNTATORI.


Turn static files into dynamic content formats.

Create a flipbook
Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.