Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //InsertionSort
- #include <iostream>
- using namespace std;
- void InsertionMax(int A[],int size)
- {
- for (int i=0;i<size-1;i++)
- {
- int j=i+1;
- int tmp=A[j];
- while (j>0 && tmp>A[j-1])
- {
- A[j]=A[j-1];
- j--;
- }
- A[j]=tmp;
- }
- }
- void InsertionMin(int A[],int size)
- {
- for (int i=0;i<size-1;i++)
- {
- int j=i+1;
- int tmp=A[j];
- while (j>0 &&tmp<A[j-1])
- {
- A[j]=A[j-1];
- j--;
- }
- A[j]=tmp;
- }
- }
- void Print (int A[],int size)
- {
- for (int i=0;i<size;i++)
- {
- cout <<A[i]<<endl;
- }
- }
- int main()
- {
- int A[]={1,8,2,55,4,0} , i , j , k ,tmp , size;
- size=sizeof(A)/sizeof(int);
- cout <<"Vargu fillestar : "<<endl;
- Print (A,size);
- InsertionMin(A ,size);
- cout << "Vargu Minimal : " << endl;
- Print (A,size);
- InsertionMax(A,size);
- cout <<"Vargu Maximal : " << endl;
- Print (A,size);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement