Listas circulares são úteis para:
1) Modelar rotas circulares como rotas aéreas volta-ao-mundo
2) Escalonamento de processos em sistemas operacionais usando o método round-robin
3) Escalonamento de impressoras em sistemas de impressão controlando várias impressoras em uma fila única
2. Listas Encadeadas Circulares
• Último elemento conecta ao primeiro.
• Implementação mais simples:
3
info próximo info próximo info próximo
nro dados
melão
doce
caro
maçã
azeda
cara
uva
irkh
barata
3. Listas Encadeadas Circulares
• Caso especial:
– Lista circular unitária.
• Atividade:
– Quais operações têm algoritmos diferentes?
– Qual é a posição mais indicada para inserir quando a posição não
importa ?
1
info próximo
nro dados
melão
doce
caro
4. Listas Encadeadas Circulares
• Alternativa para evitar mudança nos algoritmos
– nodo-sentinela funciona sempre como nodo sem informações
atachado à cabeça de lista
– lista é criada posuindo o nodo sentinela
– algoritmos não se modificam
4
info próximo info próximo info
nro dados
maçã
azeda
cara
uva
irkh
barata
melão
doce
caro
próximo
info próximo
5. Para que servem listas circulares?
• Modelagem e planejamento de rotas
circulares
– Caminho de retorno é diferente do de ida.
– Exemplo: rotas aéreas tipo volta-ao-mundo.
– Útil em sistemas de planejamento de itinerário e
de reserva global de passagens como Amadeus
Global Travel Distribution System
8. Para que servem listas circulares?
• Escalonamento de Processos (Process
Scheduling) em kernels de sistemas
operacionais multitarefa preemptivos.
– Exemplo: método round-robin (tradução:
sabiá-cíclico - não se preocupe: ninguém
usa) de escalonamento de processos com
fatia de tempo constante por processo.
9. Round Robin
CPU
Proc.#1
long int SomeFunction(); /*
int OtherFunction(); */ /* int
*/ CallingFunction() { long
int test1; register /* int */
test2; test1 = SomeFunction();
if (test1 > 0) test2 = 0; else
test2 = OtherFunction();
return test2; }.
Var1
Var2
Var3
Var4
Var5
Proc.#2
long int SomeFunction(); /*
int OtherFunction(); */ /* int
*/ CallingFunction() { long
int test1; register /* int */
test2; test1 = SomeFunction();
if (test1 > 0) test2 = 0; else
test2 = OtherFunction();
return test2; }.
Var1
Var2
Var3
Var4
Var5
Proc.#3
long int SomeFunction(); /*
int OtherFunction(); */ /* int
*/ CallingFunction() { long
int test1; register /* int */
test2; test1 = SomeFunction();
if (test1 > 0) test2 = 0; else
test2 = OtherFunction();
return test2; }.
Var1
Var2
Var3
Var4
Var5
Proc.#4
long int SomeFunction(); /*
int OtherFunction(); */ /* int
*/ CallingFunction() { long
int test1; register /* int */
test2; test1 = SomeFunction();
if (test1 > 0) test2 = 0; else
test2 = OtherFunction();
return test2; }.
Var1
Var2
Var3
Var4
Var5
long int SomeFunction(); /*
int OtherFunction(); */ /* int
*/ CallingFunction() { long
int test1; register /* int */
test2; test1 = SomeFunction();
if (test1 > 0) test2 = 0; else
test2 = OtherFunction();
return test2; }.
Var1
Var2
Var3
Var4
Var5
long int SomeFunction(); /*
int OtherFunction(); */ /* int
*/ CallingFunction() { long
int test1; register /* int */
test2; test1 = SomeFunction();
if (test1 > 0) test2 = 0; else
test2 = OtherFunction();
return test2; }.
Var1
Var2
Var3
Var4
Var5
long int SomeFunction(); /*
int OtherFunction(); */ /* int
*/ CallingFunction() { long
int test1; register /* int */
test2; test1 = SomeFunction();
if (test1 > 0) test2 = 0; else
test2 = OtherFunction();
return test2; }.
Var1
Var2
Var3
Var4
Var5
long int SomeFunction(); /*
int OtherFunction(); */ /* int
*/ CallingFunction() { long
int test1; register /* int */
test2; test1 = SomeFunction();
if (test1 > 0) test2 = 0; else
test2 = OtherFunction();
return test2; }.
Var1
Var2
Var3
Var4
Var5
10. Round Robin
CPU
Proc.#1
long int SomeFunction(); /*
int OtherFunction(); */ /* int
*/ CallingFunction() { long
int test1; register /* int */
test2; test1 = SomeFunction();
if (test1 > 0) test2 = 0; else
test2 = OtherFunction();
return test2; }.
Var1
Var2
Var3
Var4
Var5
Proc.#2
long int SomeFunction(); /*
int OtherFunction(); */ /* int
*/ CallingFunction() { long
int test1; register /* int */
test2; test1 = SomeFunction();
if (test1 > 0) test2 = 0; else
test2 = OtherFunction();
return test2; }.
Var1
Var2
Var3
Var4
Var5
Proc.#3
long int SomeFunction(); /*
int OtherFunction(); */ /* int
*/ CallingFunction() { long
int test1; register /* int */
test2; test1 = SomeFunction();
if (test1 > 0) test2 = 0; else
test2 = OtherFunction();
return test2; }.
Var1
Var2
Var3
Var4
Var5
Proc.#4
long int SomeFunction(); /*
int OtherFunction(); */ /* int
*/ CallingFunction() { long
int test1; register /* int */
test2; test1 = SomeFunction();
if (test1 > 0) test2 = 0; else
test2 = OtherFunction();
return test2; }.
Var1
Var2
Var3
Var4
Var5
long int SomeFunction(); /*
int OtherFunction(); */ /* int
*/ CallingFunction() { long
int test1; register /* int */
test2; test1 = SomeFunction();
if (test1 > 0) test2 = 0; else
test2 = OtherFunction();
return test2; }.
Var1
Var2
Var3
Var4
Var5
long int SomeFunction(); /*
int OtherFunction(); */ /* int
*/ CallingFunction() { long
int test1; register /* int */
test2; test1 = SomeFunction();
if (test1 > 0) test2 = 0; else
test2 = OtherFunction();
return test2; }.
Var1
Var2
Var3
Var4
Var5
long int SomeFunction(); /*
int OtherFunction(); */ /* int
*/ CallingFunction() { long
int test1; register /* int */
test2; test1 = SomeFunction();
if (test1 > 0) test2 = 0; else
test2 = OtherFunction();
return test2; }.
Var1
Var2
Var3
Var4
Var5
long int SomeFunction(); /*
int OtherFunction(); */ /* int
*/ CallingFunction() { long
int test1; register /* int */
test2; test1 = SomeFunction();
if (test1 > 0) test2 = 0; else
test2 = OtherFunction();
return test2; }.
Var1
Var2
Var3
Var4
Var5
11. Round Robin
CPU
Proc.#1
long int SomeFunction(); /*
int OtherFunction(); */ /* int
*/ CallingFunction() { long
int test1; register /* int */
test2; test1 = SomeFunction();
if (test1 > 0) test2 = 0; else
test2 = OtherFunction();
return test2; }.
Var1
Var2
Var3
Var4
Var5
Proc.#2
long int SomeFunction(); /*
int OtherFunction(); */ /* int
*/ CallingFunction() { long
int test1; register /* int */
test2; test1 = SomeFunction();
if (test1 > 0) test2 = 0; else
test2 = OtherFunction();
return test2; }.
Var1
Var2
Var3
Var4
Var5
Proc.#3
long int SomeFunction(); /*
int OtherFunction(); */ /* int
*/ CallingFunction() { long
int test1; register /* int */
test2; test1 = SomeFunction();
if (test1 > 0) test2 = 0; else
test2 = OtherFunction();
return test2; }.
Var1
Var2
Var3
Var4
Var5
Proc.#4
long int SomeFunction(); /*
int OtherFunction(); */ /* int
*/ CallingFunction() { long
int test1; register /* int */
test2; test1 = SomeFunction();
if (test1 > 0) test2 = 0; else
test2 = OtherFunction();
return test2; }.
Var1
Var2
Var3
Var4
Var5
long int SomeFunction(); /*
int OtherFunction(); */ /* int
*/ CallingFunction() { long
int test1; register /* int */
test2; test1 = SomeFunction();
if (test1 > 0) test2 = 0; else
test2 = OtherFunction();
return test2; }.
Var1
Var2
Var3
Var4
Var5
long int SomeFunction(); /*
int OtherFunction(); */ /* int
*/ CallingFunction() { long
int test1; register /* int */
test2; test1 = SomeFunction();
if (test1 > 0) test2 = 0; else
test2 = OtherFunction();
return test2; }.
Var1
Var2
Var3
Var4
Var5
long int SomeFunction(); /*
int OtherFunction(); */ /* int
*/ CallingFunction() { long
int test1; register /* int */
test2; test1 = SomeFunction();
if (test1 > 0) test2 = 0; else
test2 = OtherFunction();
return test2; }.
Var1
Var2
Var3
Var4
Var5
long int SomeFunction(); /*
int OtherFunction(); */ /* int
*/ CallingFunction() { long
int test1; register /* int */
test2; test1 = SomeFunction();
if (test1 > 0) test2 = 0; else
test2 = OtherFunction();
return test2; }.
Var1
Var2
Var3
Var4
Var5
12. Para que servem listas circulares?
• Sistemas de impressão que controlam várias
impressoras
– Realizam escalonamento de impressoras
(round-robin printing queue) por
disponibilidade para impressão de
documentos em uma fila de impressão
cíclica única para várias impressoras.