Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<fstream>
- using namespace std;
- int k=0;
- void countingSort(int A[],int B[],int n)
- {
- int C[k];
- for(int i=0;i<k+1;i++)
- {
- C[i]=0;
- }
- for(int j=1;j<=n;j++)
- {
- C[A[j]]++;
- }
- for(int i=1;i<=k;i++)
- {
- C[i]+=C[i-1];
- }
- for(int j=n;j>=1;j--)
- {
- B[C[A[j]]]=A[j];
- C[A[j]]=C[A[j]]-1;
- }
- }
- void romanSort(int A[],int B[],int n)
- {
- int C[k];
- for(int i=0;i<k+1;i++)
- {
- C[i]=0;
- }
- for(int j=1;j<=n;j++)
- {
- C[A[j]]++;
- }
- for(int i=1;i<=k;i++)
- {
- if(C[i]!=0)
- {
- B[i] = (C[i] * i);
- cout<<B[i]<<" ";
- }
- }
- }
- int main()
- {
- ofstream data;
- data.open("vlez.txt");
- int n,izbor;
- cout<<"vnesi golemina na nizata"<<endl;
- cin>>n;
- int A[n],B[n];
- cout<<"Vnesi elementi na nizata"<<endl;
- for(int i=1;i<=n;i++)
- {
- cin>>A[i];
- data << A[i] << " ";
- if(A[i]>k)
- {
- k=A[i];
- }
- }
- data.close();
- ofstream data1;
- data1.open("izlez.txt");
- cout<<"Izberi sort (0-Counting sort, 1-Roman Sort): ";
- cin>>izbor;
- if(izbor==0)
- {
- countingSort(A,B,n);
- for(int i=1;i<=n;i++)
- {
- cout<<B[i]<<" ";
- data1 << B[i] << " ";
- }
- }
- else if(izbor==1)
- {
- romanSort(A,B,n);
- }
- data1.close();
- cout<<endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement