swap(char **a,char **b)
{
char  *t=*a;
      *a=*b;
      *b=t;

}

#define wd 3
int main()
{

char *r[wd];
char *str="ram is good";

//splite requiere O(n) where n is number of charecter

int i=0;
int k=0;
while(str[i]!='\0')
{
             char arr[10],j=0;
             while(str[i]!=' '||str[i]!='\0')
             arr[j++]=str[i++];
             arr[j]='\0';
             r[k]=(char *)malloc(strlen(arr)+1);
             strcpy(r[k],arr);
             k++;

}

//swaping in log(m) where m is number of word

int l=0,m=wd-1;
while(l<=wd)
swap(r[l++],r[m--]);

for(i=0;i<wd;i++)
{
strcpy(str,r[i]);
strcpy(str," ");
}

print(str);
}


overall time complexity; O(n+logm)       which is O(n)  and O(n) memory
complexty

NOTE: error handling is remaining

-- 
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