Advertisement
Guest User

Untitled

a guest
Mar 4th, 2015
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.61 KB | None | 0 0
  1. #include <stdio.h>
  2. using namespace std;
  3. #define tamano 10
  4.  
  5.  
  6.  
  7.  
  8. int busquedaBinariaEnVectorV ( int v[], int n, int clave, int pri){
  9. /* Aca va el codigo de la busqueda binaria */
  10. int posic= -1;
  11. pri=1;
  12. int u=n-1;
  13. int pos;
  14. bool enc;
  15.  
  16. while ((pri <= u) and (pos == -1)){
  17. int m=(pri +u)/2;
  18.  
  19. if(v[m]==clave){
  20. pri =m+1;
  21. } else if(v[m] < clave) {
  22. pri =m+1;
  23. } else {
  24. u=m-1;
  25. }
  26.  
  27. }
  28. return posic;
  29. }
  30.  
  31.  
  32. int cargarSinRepetirEnVector ( int v[], int n, int clave){
  33.  
  34. int u = n-1;
  35. bool enc = true;
  36.  
  37.  
  38. int posic = BusquedaBinariaEnVectorV(v, n, clave); // el ultimo parametro no hace nada
  39.  
  40. if(posic != -1){
  41. return true;
  42. } else if(posic == -1){
  43. enc = false;
  44. posic = pri;
  45. for(j = u; j < pri; j--) {
  46. v[j+1]=v[j];
  47. }
  48. v[pri]=clave;
  49. n++;
  50. return false;
  51. }
  52. }
  53.  
  54.  
  55.  
  56. int main(){
  57.  
  58.  
  59. return 0;
  60. }
  61.  
  62.  
  63.  
  64. ----------------------------------------------------------------------------------------------------------------
  65.  
  66. #include <iostream>
  67. using namespace std;
  68.  
  69.  
  70. int ordenarVectorShell(int v[], int n){
  71.  
  72. int K=0;
  73. int I=0;
  74. int J=0;
  75. int n=10
  76.  
  77. double intervalo = (double)n/2;
  78.  
  79. while (intervalo > 0){
  80.  
  81. for (i=intervalo +1; i<n; i++){
  82.  
  83. while(j>0){
  84.  
  85. k=j+intervalo;
  86.  
  87. if(v[j]<=v[k]){
  88. j=-1;
  89.  
  90. }else{
  91. swap (v[j], v[k]);
  92. j=j-intervalo;
  93. }
  94. }
  95.  
  96. }
  97.  
  98. }
  99. }
  100.  
  101.  
  102.  
  103. ---------------------------------------------------------------------------------------------------------------------
  104.  
  105. #include <iostream>
  106. using namespace std;
  107. #define MAX_FIL 30
  108.  
  109. int ordenarVectorInserion(int v[], int n){
  110.  
  111. for(i=1; i<n-1; i++){
  112. int j= i;
  113. aux=v[i];
  114.  
  115. while((j>0) and (aux<v[j-1])){
  116. v[j]=v[j-1];
  117. j--;
  118. }
  119. v[j]=aux;
  120.  
  121. }
  122. }
  123.  
  124.  
  125.  
  126.  
  127.  
  128. #include <stdio.h>
  129. #define tamano 10
  130.  
  131. int ordenarVectorBurbuja ( int v[], int n)
  132. {
  133. for (i=1; i<u-1;i++){
  134.  
  135. if( v[j] > v[j+1] ){
  136.  
  137. int aux= v[j];
  138. v[j]=v[j+1];
  139. v[j+1]=aux;
  140.  
  141.  
  142. }
  143.  
  144.  
  145. }
  146.  
  147. return ;
  148. }
  149.  
  150.  
  151.  
  152. int main(){
  153.  
  154.  
  155. return 0;
  156. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement