DATA STRUCTURE Programming and Technical Programming Arrays

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?

Read Solution (Total 1)

DATA STRUCTURE Other Question

logic to expand series upto n

1, 1, 2, 10, 65, 442
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;
}