can’t understand how to do…
Arrays-Spiral Print Anticlockwise
In this question, you can maintain 4 variables as top, bottom left and right, initialise them as ,
int top=0,bottom=M-1,left=0,right=N-1;
and then take a direction variable as initialised to 0,
Then maintain the while condition as ,
while(top<=bottom && left<=right)
and then check if direction is 0, then print the array from top to bottom… and while doing that increment the direction variable… for eg,
for(int i=top;i<=bottom;i++)
{
cout<<ar[i][left]<<","<<" ";
}
left++;
direction=1;
Similarly, you need to follow up the approach for all different directions…
when to reset the direction variable
Whenever you are printing one side of matrix, you are required to update the direction variable… as I have told you in the code snippet above…