public class ReverseLink {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String str = scanner.nextLine();
char[] s = str.toCharArray();
NodeList[] nodeLists = new NodeList[s.length];
//初始化链表
for(int i=0;i<s.length;i++){
nodeLists[i] = new NodeList(s[i]);
}
//将链表连接起来
for(int i=0;i<s.length;i++){
if(i == s.length-1){
nodeLists[i].next = null;
}else {
nodeLists[i].next = nodeLists[i+1];
}
}
NodeList reverseNodeList = reverseLink(nodeLists[0]);
printNodeList(reverseNodeList);
}
//将链表反转
public static NodeList reverseLink(NodeList nodeList){
//防止边界出错
if(nodeList ==null || nodeList.next ==null){
return nodeList;
}
NodeList pre = null;
NodeList current = nodeList;
while (current !=null) {
NodeList next = current.next;
current.next = pre;
pre = current;
current = next;
}
return pre;
}
//打印链表
public static void printNodeList(NodeList nodeList){
while (nodeList !=null) {
System.out.println(nodeList.var);
nodeList = nodeList.next;
}
}
}
//定义链表
class NodeList{
char var;
NodeList next;
public NodeList(char x) {
this.var = x;
}
}