Methods to Reverse a String in Deluge
Input Example: Zohocrm
Expected Output:mrcohoZ
1.Without Using reverse() built-in function
var = "Zohocrm";
result = "";
for each e in var.tolist("")
{
// append each character in front of the existing string
result = e + result ;
}
info result;
Output
mrcohoZ2.Using reverse() built-in function
var = "Zohocrm";
result = var .reverse();
info result;
Output
mrcohoZ3.Using stack (Last-in-First-out)
var = "Zohocrm";
myList = list();
count = var.length();
info count;
final = "";
for each el in var.tolist("")
{
myList.add(el);
}
info "myList:"+myList;
topElement = "";
for each index i in myList
{
topElement = topElement+myList.get(myList.size() - (i+1)); // Get the last element
info "Top element: " + topElement;
}
Output
mrcohoZ