Rearrange array into alternate positive and negative numbers
Given an array containing both positive and negative integers, write code to rearrange the elements so that positive and negative numbers comes alternately. If positive (or negative) integers is not equal in number then extra positive (or negative) numbers should come at the end of array. For example: Input : {1, 2, -2, -5, 6, […]
Fix loop in a sorted linked list
Given a Sorted linked list which has a loop (link pointer of last node is not NULL and points to some other node). Fix the link of last node (i.e make it NULL).
Compute x^n (x to the power n)
Write a C function to compute xn which uses minimum number of multiplications. unsigned int power(double x, unsigned int n)
Maximum distance with 50 bikes each having fuel capacity of 100 kms
There are 50 bikes, each with a tank that has the capacity to go 100 kms (when the fuel is full). Fuel tanks of all the bikes are full. Using these 50 bikes, what is the maximum distance that you can go?
Implement Stack using two Queues
We have seen the code to implement a Queue using two stacks. This question is opposite of that. Use only Queue data structure to implement a Stack.
Implementing a Queue using two Stacks
We have seen how to implement Queue using a linked list and using Array as the base data structure. The question here is that given two Stacks, say S1 and S2, and no other data structure, simulate the functionality of a Queue, hence use two stacks as the base data structure for a Queue. i.e […]
Array implementation of Queue data structure
To learn the basics of the Queue visit our previous post on implementing Queue using linked list. In case the Queue is implemented using Linked list Enqueue (insertion) is about inserting a new node at the end and Dequeue (removing an element) is about deleting the first node. But, for array, things are little different.
Singly linked list implementation of Queue
In a general Queue (at any office or bank or any other place), people join the queue at the end and are removed from the front of queue. Similarly Queue data structure is a linear list of elements where element is always inserted at the end and deleted from the front.
Inserting in a linked list
Given a Singly linked list. Write functions to insert at different positions in the list: At start of the linked list. At end of the linked list. After k nodes from the start of list. After k nodes from the end of linked list. Insert in a sorted linked list.
Understanding stack data structure
Stack is a collection of objects where objects are inserted and removed in the Last-In-First-Out order. Element inserted at the end will be deleted first. It is a limited access data structure which essentially allows two operations push and pop. Push: Inserting data at the top of stack. Pop: deleting data from the top of stack. The […]