Skip to content

Instantly share code, notes, and snippets.

@EmmaG2
Last active October 28, 2024 19:20
Show Gist options
  • Save EmmaG2/05ca0e8038af9fe9bf095f58025a6af3 to your computer and use it in GitHub Desktop.
Save EmmaG2/05ca0e8038af9fe9bf095f58025a6af3 to your computer and use it in GitHub Desktop.
#define MaxCola 100
class Cola
{
private:
int num_datos;
char vector[MaxCola];
public:
Cola();
void insertar(char c);
char remover();
bool vacia();
bool llena();
};
Cola::Cola()
{
num_datos = 0;
}
void Cola::insertar(char c)
{
vector[num_datos] = c;
num_datos++;
}
char Cola::remover()
{
char temp = vector[0];
for (int i = 1; i < num_datos; i++)
vector[i - 1] = vector[i];
num_datos--;
return temp;
}
bool Cola::vacia()
{
return num_datos == 0;
}
bool Cola::llena()
{
return num_datos == MaxCola;
}
#include <ctime>
#include <iostream>
#include "cola.h"
using namespace std;
void delay(int);
int main()
{
Cola x1, x2;
char frase[50];
int veces = 0;
cout << "Escriba una frase: " << endl;
cin.getline(frase, 50);
cout << "¿Cuántas veces desea repetir?: " << endl;
cin >> veces;
for (int i = 0; frase[i] != 0; i++)
x1.insertar(frase[i]);
char letra;
for (int i = 0; i < veces; i++)
{
while (!x1.vacia())
{
delay(1);
letra = x1.remover();
cout << letra;
cout.flush();
x2.insertar(letra);
};
cout << endl;
while (!x2.vacia())
{
delay(1);
letra = x2.remover();
cout << letra;
cout.flush();
x1.insertar(letra);
};
cout << endl;
}
return EXIT_SUCCESS;
}
void delay(int seconds)
{
time_t start_time, cur_time;
time(&start_time);
do
time(&cur_time);
while ((cur_time - start_time) < seconds);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment