We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 5d8a664 + ef2a1e9 commit aedcc52Copy full SHA for aedcc52
Data Structures/Linked List/SinglyLinkedList.cpp
@@ -48,6 +48,17 @@ void PrintLL(Node* head){
48
}
49
cout<<endl;
50
51
+
52
+Node* middleElement(Node* head) {
53
+ Node* slowPtr = head;
54
+ Node* fastPtr = head;
55
+ while(fastPtr != nullptr && fastPtr->next != nullptr) {
56
+ slowPtr = slowPtr->next;
57
+ fastPtr = fastPtr->next->next;
58
+ }
59
+ return slowPtr;
60
+}
61
62
int main(){
63
//create the linked list
64
Node* head=takeInput();
@@ -62,4 +73,4 @@ int main(){
73
10 20 30 40 50
74
75
Output:
65
-10 20 30 40 50*/
76
+10 20 30 40 50*/
0 commit comments