# Delete Alternate Nodes of a Linked List

Delete Alternate Nodes of a Linked List” is a basic problem exercise for beginners based on linked list. Here, we are given a linked list and  our task is to delete every alternate node of a linked list.

```For example, we need to delete every alternate nodes of the following linked list:
11 -> 12 -> 13 -> 14 -> 15 -> 16
After deleting every other alternate nodes of a linked list:
11 -> 13 -> 15```

The steps required to delete alternate nodes of a linked list are as follows:

1. If the linked list is empty, then return.
2. Traverse the complete linked list.
3. While traversing, keep track of previous node of the node to be deleted and then delete the node by releasing  the memory allocated for the node.

#### C++ Program to delete alternate nodes of a linked list is as follows:

```/* C++ Program to delete alternate nodes of a Linked List */
#include<bits/stdc++.h>
using namespace std;

/* Structure of the node of the Linked List */
typedef struct node
{
int data;
struct node *next;
}Node;

/* Function to Insert node at the end of the linked list */
void insertEnd(Node **head,int ele)
{
/* Creating a new node */
Node *new_node = new Node();
new_node -> data = ele;
new_node -> next = NULL;

/* check whether the linked list is empty or not */

/* If Linked List is empty, then new node will become head of the linked list */
{
return;
}

/* If Linked List is not empty, then traverse the complete linked list and point the pointer
of last node of the linked list to the new node */
Node *temp = (*head);
while(temp->next != NULL)
temp = temp -> next;
temp -> next = new_node;
}
/* Function to Print the Linked List  */
{
Node *temp = head;
while(temp != NULL)
{
cout << temp -> data << " ";
temp = temp -> next;
}
cout<<endl;
}
/* Function to delete alternate nodes of the Linked List */
{
/* If Linked List is empty, simply return */
return;
Node *temp = head;
/* keep track of previous node of the node to be deleted and then
delete the node by releasing  the memory allocated for the node. */
while(temp && temp->next)
{
Node *p = temp -> next;
temp -> next = temp -> next -> next;
temp = temp -> next;
free(p);
}
}
int main()
{
Node *head = NULL;
/* Inserting Some Nodes in the Linked List */
cout<<"Before Deleting Alternate Nodes of the Linked List:\n";

cout<<"\nAfter Deleting Alternate Nodes of the Linked List:\n";
```OUTPUT: