Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- using namespace std;
- void swap(long long *xp, long long *yp)
- {
- int temp = *xp;
- *xp = *yp;
- *yp = temp;
- }
- int sevenCount(long long arrN)
- {
- int count = 0;
- while (arrN > 0)
- {
- int digit = arrN%10;
- if(digit == 7)
- {
- count++;
- }
- arrN /= 10;
- }
- return count;
- }
- void MoDbubbleSort(long long arr[], int n)
- {
- int i, j;
- for (i = 0; i < n-1; i++)
- for (j = 0; j < n-i-1; j++)
- if (sevenCount(arr[j]) > sevenCount(arr[j+1]))
- swap(&arr[j], &arr[j+1]);
- }
- void bubbleSort(long long arr[], int n)
- {
- int i, j;
- for (i = 0; i < n-1; i++)
- for (j = 0; j < n-i-1; j++)
- if (arr[j] > arr[j+1])
- swap(&arr[j], &arr[j+1]);
- }
- void printArray(long long arr[], int size)
- {
- int i;
- for (i=0; i < size; i++)
- cout<<arr[i]<<" ";
- }
- int main()
- {
- long long arr[] = {17, 17377, 41, 973, 427, 277};
- int n = sizeof(arr)/sizeof(arr[0]);
- bubbleSort(arr, n);
- MoDbubbleSort(arr, n);
- printArray(arr, n);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement