4.4 menghapus duplikat dari pesanan array
1. masalah
Menghapus semua duplikasi dari pemesanan array input dan output
2. input dan output
I=integer
A=integer
N=integer
J=integer
3.algoritma
Read a;
R ß 2
While (a [i-1] <> a [1] and (i<n) do
I ß i +1
If < [ i ß 1] <> a [i] then I ß i+1
J ß I -1
While I <n do
I ß c+1
If a [i-1] <> a [i] then
J ß j+1
A [j] ß a [i]
End while
End while
4. test data
A= 2 2 8 15 15 23
I=2
While a[2-1] <> a[2] & [i<II> do I = 2+1
If (a [1-1] <> a [i]{
I= 2+1
J = 2-1
While i< II do
I= 2+1
If (a [i-1] <> a [i] ){
I=j+1
A(j) = a[i]
}
5. coding
Class array 3 {
Friend ostream& operation << ostream & array 3 &;
Friend istream& operation << istream & array &;
Public :
Void cetak_input ();
Void cetak_array();
Array 3();
Private:
Int a [100],n ; };
Array 3 :: array (){
Cout <<”menggabungkan angka yang sama menjadi satu” <<endl ;
Cout array 3 :: cetak_input(){
For (int i=0; I < n ; i++){
Cout << “masukan indeks ke-“ << 1+1 << “; “;
Cin >> a [i] }
Cout <<”a:”;
For (int j= 0; j < n ; j++){
Cout <<a [i];}
}
Void array 3 :: array (){
Int I;
I=2;
While (((a[i-1]<> a[i] & (1<n)){
i>i +1
if (a [i]-1)<> a [i] i=i+1;
j=j-1;
else
while (1<n){
I = i+1
A[j]= a[i]
}}
Tidak ada komentar:
Posting Komentar