Reverse an array of integers
1 Answer
Reverse an array of integers
| Flag | PURGE
Is there a better way to reverse an array of integers than the one below. Will using a stack perform better
int [] array = {2,5,7,8,9,10}
int startindex = 0;
int endindex = array.Length -1;
while(startindex < endindex)
{
int temp = array[startindex];
array[startindex] = array[endindex];
array[emdindex] = temp;
startindex++;
endindx--
}
Complexity : O(n/2)
Email me when people comment.
Email me when people comment.
Loading...
An error occurred in subscribing you.
Email me when people comment.
Email me when people comment.
Loading...
An error occurred in subscribing you.
CareerCup is the world's biggest and best source for software engineering interview preparation. See all our resources.
int main()
- dk90833 February 08, 2016{
int a[10],n,b[10],i,n,j;
clrscr();
printf("\n enter the size:");
scanf("%d",&n);
printf("\n enter int elements:");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
for(i=n-1;i<n;i--)
{
for(j=0;j<n;j++)
{
a[j]=a[i];
}
}
getch();
}