Delete Middle of Linked List
Submissions: 16389   Accuracy:


  Difficulty: Easy   Marks: 2

Given a singly linked list, delete middle  of the linked list. For example, if given linked list is 1->2->3->4->5 then linked list should be modified to 1->2->4->5.
If there are even nodes, then there would be two middle nodes, we need to delete the second middle element. For example, if given linked list is 1->2->3->4->5->6 then it should be modified to 1->2->3->5->6.

If the input linked list is NULL, then it should remain NULL. If the input linked list has 1 node, then this node should be deleted and new head should be returned.

First line of input contains number of testcases T. For each testcase, there will be two line of input, first of which contains number of nodes in the linked list and next line contains elements in the nodes of linked list.

Your function should return head  of the modified linked list.  If linked list is empty then it should return NULL.

User Task:
The task is to complete the function deleteMid() which should delete the middle element from linked list. 

1 <=T<= 50
1 <=N<= 1000
1 <=value<= 1000


1 2 3 4 5
2 4 6 7 5 1

1 2 4 5
2 4 6 5 1

Testcase 1
: After deleting middle of the linked list, 3 will be deleted and the list will be as 1, 2, 4, 5.


** For More Input/Output Examples Use 'Expected Output' option **

Contributor: Amit Khandelwal, Harshit Sidhwa
Author: kartik

If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.

Need help with your code? Please use, generate link and share the link here.

to report an issue on this page.