TLE in OddEven LL

#include
using namespace std;

class ListNode
{
public:
int data;
ListNode* next;
ListNode(int val){
this->data = val;
this->next = NULL;
}

};

ListNode* oddEven(ListNode* head){
if(head == NULL) return NULL;
ListNode* oh,*ot,*eh,et;
oh=ot=head;
eh=et = head->next;
ListNode
temp = eh->next;
oh->next = eh->next = NULL;
// we will do insertion at the end
while(temp != NULL){
// for odd one
ot->next = temp;
ot = temp;
temp = temp->next;
ot->next = NULL;
if(temp == NULL){break;}

	// for even one
	et->next = temp;
	et = temp;
	temp = temp->next;
	et->next = NULL;
}
ot->next = eh;
return oh;

}

void insertAtTail(ListNode *&head, int data) {
if(head == NULL) {
head = new ListNode(data);
return;
}
ListNode *tail = head;
while(tail->next != NULL) {
tail = tail->next;
}
tail->next = new ListNode(data);
return;
}

void createList(ListNode* head){
int data;
cin>>data;
while(data!=-1) {
insertAtTail(head, data);
cin>>data;
}
}

int main(){
int n;
cin>>n;
cout<<"Original List: ";
ListNode* head = NULL;
createList(head);
cout<<"Modified List: "<<oddEven(head)<<endl;
return 0;
}

Hey @Nikhil-Rajput-1327861567562217
Please share your code in Coding Blocks IDE

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.