#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
int S[8] = {2, 4, 5, 1, 3, 6, 7, 9};
int A[8] = {12, 13, 14, 15, 5, 6, 7, 24} ;
iter_swap (S+4, A+3);
for (int i = 0; i<8; i++)
cout << S[i] <<" ";
cout<<"\n";
for (int j = 0; j<8; j++)
cout<< A[j] <<" ";
cout<<"\n";
return 0 ;
}
==========================
#include<iostream>
# include<algorithm>
using namespace std;
int main()
{
char S1[] = "AA";
char S2[] ="ZZ";
char B[] = "hitung";
char C[] ="hitungan";
bool b1 =lexicographical_compare(S1, S1+1, S2, S2+1);
cout<<"b1 = "<< b1<<endl;
bool b2 =lexicographical_compare(S2, S2+1 ,S1, S1+1 );
cout<<"b2 = "<< b2<<endl;
bool b3 = lexicographical_compare(S1, S1+1, S1, S1+1);
cout<<"b3 = "<<b3<<endl;
bool b4 = lexicographical_compare(B, B+6, C, C+9);
cout<<"b4 = "<< b4<<endl;
return 0 ;
}
==========================
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
int S1[] = {11, 12, 13, 16, 16, 19, 20, 20, 20, 22, 24};
int* ptr1 = lower_bound(S1, S1+11, 20);
cout <<"lower_bound untuk 20 = "<< (int*)ptr1 - S1 <<endl;
int* ptr2 = lower_bound(S1, S1+11, 16);
cout <<"lower_bound untuk 16 = "<< (int*)ptr2 - S1 <<endl;
int *uptr1 = upper_bound (S1, S1+11, 16);
cout <<"upper_bound dari 16 = "<< (int*)uptr1 - S1 <<endl;
int* uptr2 = upper_bound (S1, S1+11, 20);
cout <<"upper_bound dari 20 = "<< (int*)uptr2 - S1 <<endl;
return 0 ;
}
================================
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
int S[13] = {10, 12, 22, 24, 34, 51, 71, 13, 16, 177, 106, 6, 7};
make_heap(S, S+13);
for ( int i =0; i<13; i++)
cout << S[i] <<" ";
cout<<"\n";
return 0;
}
============================
#include<iostream>
# include<algorithm>
using namespace std;
int main()
{
int S1[] = {10, 12, 40};
int S2[] = {34, 51, 71, 106, 177};
int A[8];
int B[6];
merge(S1, S1+3, S2, S2+5, A);
for (int i =0; i<8 ;i++)
cout<< A[i]<<" ";
cout<<"\n";
merge(S2, S2+4, S1, S1+2, B);
for (int k =0; k<6 ;k++)
cout<< B[k]<<" ";
cout<<"\n";
return 0 ;
}
==================================
#include<iostream>
# include<algorithm>
using namespace std;
int main()
{
int S1[] = {19, 20, 11, 12, 113, 216};
cout<< *min_element(S1, S1+6) <<endl; //nilai dari elemen minimum
const int *ptr = min_element(S1, S1+6);
cout<< (int*)ptr - S1 <<endl; //indeks dari elemen minimum
return 0 ;
}
======================
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
char S1[] = "Komputer, Komputar, Komputor";
char S2[] = "Komputer, Komputer, Komputer";
int m = strlen(S1);
pair<char*, char*> p = mismatch( S1, S1+m, S2);
char* S1ptr= p.first;
char* S2ptr= p.second;
cout<<"Panjang = "<< m <<endl;
cout<<"Lokasi pertama dari ketidakcocokan di dalam string S1 adalah pada "<<S1ptr - S1<<endl;
cout<<"Lokasi pertama dari ketidakcocokan di dalam string S2 adalah pada "<<S2ptr - S2<<endl;
return 0;
}
============================
#include <iostream>
#include<algorithm>
using namespace std;
void main()
{
char A[5] = "XYZ";
for( int k =0; k<6;k++)
{
next_permutation(A, A+3);
cout<<A<<" ";
}
cout<<"\n";
}
========================
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
int S[10] = {10, 12, 22, 24, 34, 51, 171, 13, 16, 170};
nth_element(S, S+4, S+10);
for (int i =0; i<10; i++)
cout << S[i] <<" ";
cout<<"\n";
return 0 ;
}
Tidak ada komentar:
Posting Komentar