Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Example program
- #include <iostream>
- #include <string>
- #include <cstring>
- void swap(int *first, int *second) {
- int temp = *first;
- *first = *second;
- *second = temp;
- }
- void smallSort2(int *a, int *b, int *c) {
- if (*a > *c) swap(a, c);
- if (*a > *b) swap(a, b);
- if (*b > *c) swap(b, c);
- }
- void testSmallSort2() {
- int a = 14;
- int b = -90;
- int c = 22;
- smallSort2(&a, &b, &c);
- std::cout << a << ", " << b << ", " << c;
- }
- void printArray(std::string name, double *arr, int size) {
- std::cout << "Array: {\n Name: \""<< name << "\",\n Length: " << size << ",\n Values: [";
- for(int i = 0; i < size; i++) {
- if (i == size - 1)
- std::cout << arr[i] << "";
- else
- std::cout << arr[i] << ", ";
- }
- std::cout << "]\n}" << std::endl;
- }
- void repeatArray(double *arr, int size) {
- double *temp = new double[size * 2];
- for(int i = 0; i < size; i++) {
- temp[i] = arr[i];
- temp[i + size] = arr[i];
- }
- printArray("arr", arr, size);
- printArray("temp", temp, size * 2);
- // Free arr old array
- // Point arr to temp
- // Free temp
- }
- int main() {
- const int SIZE = 3;
- double *myArray = new double[SIZE];
- for(int i = 0; i < SIZE; i++)
- myArray[i] = (i+1)*2;
- repeatArray(myArray, SIZE);
- printArray("myArray", myArray, SIZE * 2);
- delete []myArray;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement