Might as well start off with the links first.
This one is two the assignment i need to do. So if you don't understand the discription please click the link.
OK, what i need to do is take the text from t1 split it in half (not sure about using odd numbered amount of text but i have it in my code anyway) and then the take the frist half as the new output for t1 and the second half for t2.
Example:
Input
t1 = help
t2 = blank_for_now
Output
t1 = he
t2 = lp
Here is the code i have so far:
If anyone can help me with this it would be a big help. I am almost there but seem to be stuck right now.
Help is appriciated, thanks.
This one is two the assignment i need to do. So if you don't understand the discription please click the link.
OK, what i need to do is take the text from t1 split it in half (not sure about using odd numbered amount of text but i have it in my code anyway) and then the take the frist half as the new output for t1 and the second half for t2.
Example:
Input
t1 = help
t2 = blank_for_now
Output
t1 = he
t2 = lp
Here is the code i have so far:
Code:
procedure_body Split (
alters Text& t1,
consumes Text& t2
)
{
Integer pos = 0;
if(t1.Length () mod 2 == 1)
{
while(pos <= t1.Length()/2)
{
if(t1.Length () mod 2 == 1)
{
t2.Add(pos,t1[t1.Length ()/2+1]);
t1.Remove(t1.Length ()/2+1, t1[t1.Length ()/2+1]);
pos++;
}
else
{
t2.Add(pos,t1[t1.Length ()/2+pos]);
t1.Remove(t1.Length ()/2+pos, t1[t1.Length ()/2+pos]);
pos++;
}
}
}
else
{
while(pos <= t1.Length()/2)
{
if(t1.Length () mod 2 ==1)
{
t2.Add(pos,t1[t1.Length ()/2+1]);
t1.Remove(t1.Length ()/2+1, t1[t1.Length ()/2+1]);
pos++;
}
else
{
t2.Add(pos,t1[t1.Length ()/2+pos]);
t1.Remove(t1.Length ()/2+pos, t1[t1.Length ()/2+pos]);
pos++;
}
}
}
}
If anyone can help me with this it would be a big help. I am almost there but seem to be stuck right now.
Help is appriciated, thanks.