Advertisement
Guest User

Untitled

a guest
Apr 21st, 2018
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.03 KB | None | 0 0
  1. // Autor: Francisco Jesús Beltrán Moreno
  2. // Ejercicio 1
  3.  
  4. void creacion(string entrada, string salida)
  5. {
  6.     struct elemento
  7.     {
  8.         int valor;
  9.         int posicion;
  10.     };
  11.  
  12.     ifstream f_entrada;
  13.     ofstream f_salida;
  14.  
  15.     f_entrada.open("entrada", ios::binary);
  16.     f_salida.open("salida", ios::binary);
  17.  
  18.     if(!f_entrada.fail())
  19.     {
  20.         while(!f_entrada.eof())
  21.         {
  22.             elemento temp;
  23.             int posicion_f;
  24.  
  25.             f_entrada.read((char*)&temp, sizeof(elemento));
  26.             posicion_f = temp.posicion + 1;
  27.  
  28.             f_salida.seekp(posicion_f, ios::beg);
  29.             f_salida.write((char*)&temp, sizeof(elemento));
  30.         }
  31.     }
  32.  
  33.     f_entrada.close();
  34.     f_salida.close();
  35.    
  36. }
  37.  
  38. // Ejercicio 2
  39. // Salida -> 1<=i<=longitud();
  40.  
  41. int Cola::observar(int i)
  42. {
  43.     int elemento;
  44.  
  45.     for(int j=0; j<longitud(); j++)
  46.     {
  47.         if(j == i-1)
  48.             elemento = primero();
  49.  
  50.         encolar(primero());
  51.         desencolar();
  52.     }
  53.  
  54.     return elemento;
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement