lines = 0;
string last_n_lines[n];
//read each line into a circular buffer
while(getline(file,last_n_lines[lines%n]))
{
lines++;
}
// if number of lines < n
// then print all of them
if(lines<=n)
{
start = 0;
count = lines;
}
else
{
start = lines%n;
count = lines;
}
//Now print all of them.
for(i=0;i<count;i++)
{
cout<<last_n_lines[(start+i)%n];
}
For example if we have
n = 4 and lines = 7
after reading we have 5,6,7 and 4 th lines in array last_n_lines;
start = lines%n=3,
So, we print 4, 5, 6 and 7 lines
--
With love and regards,
Sairam Ravu
I M.Tech(CS)
Sri Sathya Sai Institute of Higher Learning
"To live life, you must think it, measure it, experiment with it,
dance it, paint it, draw it, and calculate it"
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.