Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Quick find
- // https://www.coursera.org/learn/algorithms-part1/lecture/EcF3P/quick-find
- #include <iostream>
- #include <string>
- using namespace std;
- int array[10] = {0,1,2,3,4,5,6,7,8,9};
- int secondValue = 0;
- void unionN(int first, int second)
- {
- secondValue = array[second];
- array[second] = array[first];
- for(int i =0; i<sizeof(array)/sizeof(array[0]); i++)
- {
- if (array[i] == secondValue)
- {
- array[i] = array[first];
- }
- }
- }
- void printArray()
- {
- for(int i =0; i<sizeof(array)/sizeof(array[0]); i++)
- {
- cout << "Index: " << i << " value: "<< array[i] << endl;
- }
- }
- int main()
- {
- unionN(1,2);
- unionN(5,6);
- unionN(1,5);
- printArray();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement