y insertion sort givin tle?

On Fri, Aug 17, 2012 at 12:05 PM, Sairam Ravu <ravu...@gmail.com> wrote:

> #include <iostream>
> #include <map>
> #include <stdlib.h>
>
> using namespace std;
>
> int main()
> {
>  int testcases;
>  cin >> testcases;
>
>  int Inputsize[200000];
>  int  *Output[testcases];
>
>  int i;
>
> for(i=0;i<testcases;i++)
>  {
>         int inputsize=0;
>         int *Order;
>    cin >> inputsize;
>
>
>
>         Order = (int *)malloc(sizeof(int)*(inputsize+1));
>
>    int j;
>         int value;
>         for(j=0;j<inputsize;j++)
>         {
>          cin >> value;
>          Inputsize[j] = value;
>          Order[j] =  j+1;
>         }
>         Order[j] = '\0';
>
>         int temp;
>         int tempOrder;
>         int tempIndex;
>
>
>         for(j=0;j<inputsize;j++)
>         {
>
>          temp = Inputsize[j];
>          tempIndex = j;
>
>          while(temp)
>          {
>
>                 tempOrder = Order[tempIndex-1];
>                 Order[tempIndex-1] = Order[tempIndex];
>                 Order[tempIndex] = tempOrder;
>                 tempIndex--;
>                 temp--;
>
>          }
>
>         }
>
>         //Now have a map between the Order and the index of it
>
>         map<int,int> MapOrder;
>         map<int,int>::iterator  iter;
>
>         for(j=0;j<inputsize;j++)
>         {
>          MapOrder[Order[j]] = j+1;
>         }
>
>
>         for(j=0,iter=MapOrder.begin();iter!=MapOrder.end();iter++,j++)
>         Order[j] = iter->second;
>
>         Output[i] = Order;
>
>  }
>
>  //Now print the output
>
> int j;
>  for(i=0;i<testcases;i++)
>  {
>         for(j=0;Output[i][j]!='\0';j++)
>                 cout<<Output[i][j]<<" ";
>         cout<<endl;
> }
>
> }
>
>
> Code is giving correct results- but it is running out of time. Can you
> suggest some way to get out of it?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
>


-- 
*
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Thanks And Sincere Regards
Apoorv Gupta
Btech Final Year
Computer Science And Engineering
MNNIT Allahabad
*

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to