top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

C Program to sort an array of 1000 char variables in optimization way with respect to time and memory?

+1 vote
319 views

Please help me with c program which takes less memory and time to sort a unsorted array of 1000 chars, its order should not be more then O(N) and memory should be most least as possible. Use bit fields and share the program?

posted Mar 15, 2016 by Suchakravarthi Sripathi

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button
Try any standard soring ALGO like quicksort?

1 Answer

0 votes
//c++ program to sort characters 
// Time complexity is O(log n)
//Space complexity is O(n)
    #include<iostream>
    #include<bits/stdc++.h>
    #include<algorithm>
    #include<vector>
    int main()
    {
    vector<char> v;
    char ch;
    for(int i=1;i<=1000;i++)
    cin>>ch,v.push_back(ch);
    sort(v.begin(),v.end());
    cout<<"\n Sorted character array is\n";
    for(vector<char>::iterator it=v.begin();it!=v.end();it++)
    cout<<*it;
    return 0;
    }
answer Mar 20, 2016 by Rajan Paswan
...