Advertisement
Sajib_Ahmed

Insertion sort and delete duplicate

Mar 4th, 2021
610
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.87 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main()
  4. {
  5.  
  6.     string name[9]= {"John", "Zahid", "Zahid", "Enam","Enam","Scott","Colin","Timothy","Zenon"};
  7.     int Length=9;
  8.     int i,k,j;
  9.     string Temp;
  10.  
  11.     for ( i = 1; i < Length; ++i)
  12.     {
  13.         Temp= name[i];
  14.  
  15.         for ( k = i-1; k >= 0 && name[k] > Temp; k--)
  16.         {
  17.             name[k+1] = name[k];
  18.         }
  19.         name[k+1] = Temp;
  20.     }
  21.     cout<<"All my contacts name: \n";
  22.     for(i=0; i<Length; i++)
  23.     {
  24.         cout<<name[i]<<" \n";
  25.     }
  26.  
  27.     for(i=0;i<Length;++i){
  28.         for(j=i+1;j<Length;)
  29.         {
  30.             if(name[i]==name[j])
  31.             {
  32.                 for(k=j;k<Length-1;++k)
  33.                     name[k]=name[k+1];
  34.  
  35.                 --Length;
  36.             }
  37.             else
  38.                 ++j;
  39.         }
  40.     }
  41.     cout<<"\nAll my contacts name with out Duplicate :\n";
  42.     for(i=0; i<Length; i++)
  43.     {
  44.         cout<<name[i]<<" \n";
  45.     }
  46.     cout<<endl;
  47. }
  48.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement