Examples:

```Example 1:
Input: 1 2 3 4 5
Output: 2 3 4 5

Example 2:
Input: NULL
Output: NULL

Example 3:
Input: 1
Output: NULL```

### Solution:

DisclaimerDon’t jump directly to the solution, try it out yourself first.

### Solution 1:

Approach 1: O(n) approach

In this approach, we iterate to the last node of the circular linked list and perform the following steps:

1. Point the next pointer of the last node to point to the second node of the linked list.
3. Return the second node as the new head of the linked list.

The following diagram explains the above approach Code:

## C++ Code

``````#include <iostream>
using namespace std;

struct node {
int data;
node * next;
node(int d) {
data = d;
next = NULL;
}
};
node * deletion_begg(node * head) {
if (head == NULL) return NULL;
return NULL;
}
while (current -> next != head) {
current = current -> next;
}
current -> next = head -> next; // step 1
return current -> next; // step 3

}
do {
cout << current -> data << " ";
current = current -> next;
cout<<endl;
}
int main() {
node * head = new node(10);
head -> next = new node(20);
cout<<"Before deletion:"<<endl;
cout<<"After deletion:"<<endl;
return 0;
}
``````

Output:

Before deletion:
10 20
After deletion:
20

Time Complexity: O(n)

Space Complexity: O(1)

## Java Code

``````class node {
int data;
node next;
node(int d) {
data = d;
next = null;
}
}
public class Main {
return null;
}
return null;
} else {
current = current.next;
}
current.next = head.next; // step 1
// step 2 : Thanks to java garbage collection mechanism
return current.next; // step 3
}
}
public static void printlist(node head) {
do {
System.out.print(current.data + " ");
current = current.next;
System.out.println();
}
public static void main(String args[]) {
System.out.println("Before deletion:");
System.out.println("After deletion");
}
}
``````

Output:

Before deletion:
10 20 30
After deletion:
20 30

Time Complexity: O(n)

Space Complexity: O(1)

### Solution 2:

Approach 2: O(1) Approach

In this approach, we perform the following steps:

1. Copy the data of the second node into the head node.
2. Store the second node in a temp node.
3. Change the next pointer of the head node to point to the third node.
4. Delete the temp node.

The following diagram explains the above approach   Code:

## C++ Code

``````#include <iostream>
using namespace std;

struct node {
int data;
node * next;
node(int d) {
data = d;
next = NULL;
}
};
node * deletionBegg(node * head) {
head -> data = head -> next -> data; // step 1
node * temp = head -> next; // step 2
head -> next = head -> next -> next; // step 3
delete temp; // step 4
}
do {
cout << current -> data << " ";
current = current -> next;
cout<<endl;
}

int main() {
node * head = new node(10);
head -> next = new node(20);
cout<<"Before deletion:"<<endl;
cout<<"After deletion:"<<endl;
return 0;
}
``````

Output:

Before deletion:
10 20
After deletion:
20

Time Complexity: O(1)

Space Complexity: O(1)

## Java Code

``````class node {
int data;
node next;
node(int d) {
data = d;
next = null;
}
}
public class Main {
// node newnode = new node(x);
return null;
}
return null;
} else {

// step 2 & step 4: thanks to JAVA garbage collection mechanism
}
}
public static void printlist(node head) {
do {
System.out.print(current.data + " ");
current = current.next;
System.out.println();
}

public static void main(String args[]) {
System.out.println("Before deletion:");
System.out.println("After deletion");
}
}
``````

Output:

Before deletion:
10 20 30
After deletion
20 30

Time Complexity: O(1)

Space Complexity: O(1)