Skip to content

Instantly share code, notes, and snippets.

@WOLOHAHA
Last active August 29, 2015 14:02
Show Gist options
  • Save WOLOHAHA/5fd7b3cb7308ec906646 to your computer and use it in GitHub Desktop.
Save WOLOHAHA/5fd7b3cb7308ec906646 to your computer and use it in GitHub Desktop.
Implement a function void reverse(char* str) in C or C++ which reverses a null-terminated string.
public class Main {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Main so = new Main();
so.reverse("abcdefghijk");
}
public void reverse(String s){
if(s==null)
return;
if(s.length()==1)
return;
char[] c=s.toCharArray();
int i=0;
int j=s.length()-1;
while(i<j){
char temp=c[i];
c[i]=c[j];
c[j]=temp;
i++;
j--;
}
String m=new String(c);
s=m;
System.out.println(s);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment