Skip to content

Commit a433c76

Browse files
authored
Merge pull request mouredev#7399 from devcherry1/patch-12
#7 - C#
2 parents 07aca8c + 72b3221 commit a433c76

File tree

1 file changed

+89
-0
lines changed

1 file changed

+89
-0
lines changed
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
using System;
2+
3+
class Program
4+
{
5+
static void Main()
6+
{
7+
Stack<string> urls = new Stack<string>();
8+
Extra.Navegador(urls);
9+
10+
Queue<string> cola = new Queue<string>();
11+
Extra.Imprimir(cola);
12+
}
13+
}
14+
class Extra
15+
{
16+
public static void Navegador(Stack<string> urls)
17+
{
18+
Console.WriteLine($"Ingrese una url valida o seleccione una de estas opciones: " +
19+
$"\n 1.Atras" +
20+
$"\n 2.Salir");
21+
string opcion = Console.ReadLine();
22+
23+
switch (opcion)
24+
{
25+
case "1":
26+
if (urls.Count > 0)
27+
{
28+
urls.Pop();
29+
if (urls.Count > 0)
30+
{
31+
Console.WriteLine($"Has regresado a la web: {urls.Peek()}");
32+
}
33+
else
34+
{
35+
Console.WriteLine("No hay más páginas en el historial.");
36+
}
37+
}
38+
else
39+
{
40+
Console.WriteLine("El historial está vacío. No puedes regresar.");
41+
}
42+
break;
43+
case "2":
44+
Console.WriteLine("Saliendo del navegador.");
45+
return;
46+
default:
47+
urls.Push(opcion);
48+
Console.WriteLine($"Has navegado a la web {urls.Peek()}");
49+
break;
50+
}
51+
Navegador(urls);
52+
}
53+
public static void Imprimir(Queue<string> cola)
54+
{
55+
Console.WriteLine($"Ingrese un documento o seleccione una de estas opciones: " +
56+
$"\n 1.Imprimir" +
57+
$"\n 2.Salir");
58+
string opcion = Console.ReadLine();
59+
60+
switch (opcion)
61+
{
62+
case "1":
63+
if (cola.Count > 0)
64+
{
65+
if (cola.Count > 0)
66+
{
67+
Console.WriteLine($"El documento {cola.Dequeue()} ha sido impreso");
68+
}
69+
else
70+
{
71+
Console.WriteLine("No hay más documentos para imprimir.");
72+
}
73+
}
74+
else
75+
{
76+
Console.WriteLine("No hay más documentos para imprimir.");
77+
}
78+
break;
79+
case "2":
80+
Console.WriteLine("Apagando impresora.");
81+
return;
82+
default:
83+
cola.Enqueue(opcion);
84+
Console.WriteLine($"El documento {opcion} ha sido agregado");
85+
break;
86+
}
87+
Imprimir(cola);
88+
}
89+
}

0 commit comments

Comments
 (0)