In this video instead of using a helper class, we can swap the top and bottom elements which take splace in O(n) time will it be a better solution?
Code:
temp=location(first element)—>O(n)
top=this.top
ref=top;
while(top>temp)
{
t=data[temp]
data[top]=data[temp]
data[temp]=t
top–;
temp++;
}
top=ref;
Will this be a better code becazuse we are not using extra memory right?