Advertisement
Guest User

Untitled

a guest
May 24th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | None | 0 0
  1. // Example program
  2. #include <iostream>
  3. #include <string>
  4. #include <cstring>
  5.  
  6. void swap(int *first, int *second) {
  7. int temp = *first;
  8. *first = *second;
  9. *second = temp;
  10. }
  11.  
  12. void smallSort2(int *a, int *b, int *c) {
  13. if (*a > *c) swap(a, c);
  14. if (*a > *b) swap(a, b);
  15. if (*b > *c) swap(b, c);
  16. }
  17.  
  18. void testSmallSort2() {
  19. int a = 14;
  20. int b = -90;
  21. int c = 22;
  22.  
  23. smallSort2(&a, &b, &c);
  24.  
  25. std::cout << a << ", " << b << ", " << c;
  26. }
  27.  
  28. void printArray(std::string name, double *arr, int size) {
  29. std::cout << "Array: {\n Name: \""<< name << "\",\n Length: " << size << ",\n Values: [";
  30. for(int i = 0; i < size; i++) {
  31. if (i == size - 1)
  32. std::cout << arr[i] << "";
  33. else
  34. std::cout << arr[i] << ", ";
  35. }
  36.  
  37. std::cout << "]\n}" << std::endl;
  38. }
  39.  
  40. void repeatArray(double *arr, int size) {
  41. double *temp = new double[size * 2];
  42.  
  43. for(int i = 0; i < size; i++) {
  44. temp[i] = arr[i];
  45. temp[i + size] = arr[i];
  46. }
  47.  
  48. printArray("arr", arr, size);
  49. printArray("temp", temp, size * 2);
  50.  
  51. // Free arr old array
  52. // Point arr to temp
  53. // Free temp
  54. }
  55.  
  56. int main() {
  57. const int SIZE = 3;
  58. double *myArray = new double[SIZE];
  59.  
  60. for(int i = 0; i < SIZE; i++)
  61. myArray[i] = (i+1)*2;
  62.  
  63. repeatArray(myArray, SIZE);
  64.  
  65. printArray("myArray", myArray, SIZE * 2);
  66.  
  67. delete []myArray;
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement