# April 2015

## Problem Statement

You’re given the pointer to the head node of a linked list and you need to print all its elements in order, one element per line. The head pointer may be null, i.e., it may be an empty list. In that case, don’t print anything!

## Source code:

`````` /*
Print elements of a linked list on console
head pointer input could be NULL as well for empty list
Node is defined as
struct Node
{
int data;
struct Node *next;
}
*/
{
// This is a "method-only" submission.
// You only need to complete this method.
}
}
``````

## Problem Statement

You're given the pointer to the head node of a linked list and you need to print all its elements in reverse order from tail to head, one element per line. The head pointer may be null meaning that the list is empty - in that case, don't print anything!

## Soruce code:

`````` /*
Print elements of a linked list in reverse order as standard output
head pointer could be NULL as well for empty list
Node is defined as
struct Node
{
int data;
struct Node *next;
}
*/
{
// This is a "method-only" submission.
// You only need to complete this method.
int a[100],i=0;
i++;
}
for(int j = i-1;j>=0;j--){
cout<<a[j]<<endl;
}
}
``````

## Problem Statement

You’re given the pointer to the head node of a doubly linked list. Reverse the order of the nodes in the list. The head node might be NULL to indicate that the list is empty.

## Source Code:

`````` /*
Reverse a doubly linked list, input list may also be empty
Node is defined as
struct Node
{
int data;
Node *next;
Node *prev;
}
*/
{
Node *cur = head,*temp = new Node;
// Complete this function
// Do not write the main method.
while(cur !=NULL){
temp->next = cur->next;
temp->prev = cur->prev;
cur->next = temp->prev;
cur->prev = temp->next;
cur = temp->next;
if(cur!=NULL){
}
}
}  ``````

## Problem Statement

You're given the pointer to the head node of a sorted linked list, where the data in the nodes is in ascending order. Delete as few nodes as possible so that the list does not contain any value more than once. The given head pointer may be null indicating that the list is empty.

## Source code:

`````` /*
Remove all duplicate elements from a sorted linked list
Node is defined as
struct Node
{
int data;
struct Node *next;
}
*/