DATA STRUCTURE Programming and Technical Programming

EXAMPLE:
Input=['1','0','1','2','3','0','3','4','0']
Output:
['1', '1', '2', '3', '3', '4', '0', '0', '0']

// Function to move all zeros present in the array to the end
void reorder(int A[], int n)
{
// k stores index of next available position
int k = 0;

// do for each element
for (int i = 0; i < n; i++)
{
// if current element is non-zero, put the element at
// next free position in the array
if (A[i] != 0)
A[k++] = A[i];
}

// move all 0's to the end of the array (remaining indices)
for (int i = k; i < n; i++)
A[i] = 0;
}

// Move all zeros present in the array to the end
int main(void)
{
int A[] = { ..... };
int n = sizeof(A) / sizeof(A[0]);

reorder(A, n);

for (int i = 0; i < n; i++)
printf("%d ", A[i]);

return 0;
}

Read Solution (Total 0)

DATA STRUCTURE Other Question

A queue is implemented as a single linked list. Each node has an element and pointer to
another node. Rear and Front contain the addresses of the Rear and Front nodes
respectively. If the condition (rear isequal front) is true and neither is NULL, what do we infer
about the linked list?
Problem Statement:

Problem statement is very easy . On a positive integer, you can perform any one of the following 3 steps.

1.) Subtract 1 from it. ( n = n - 1 )

2.) If its divisible by 2, divide by 2. ( if n % 2 == 0 , then n = n / 2 )

3.) If its divisible by 3, divide by 3. ( if n % 3 == 0 , then n = n / 3 )

Given a positive integer n and you task is find the minimum number of steps that takes n to one .