Pages

Thursday, June 26, 2025

Iterative Search in Linked List in C++

 int searchItr(int key) {
Node* temp = head;

int idx = 0;


while(temp != NULL) {
if(temp->data == key) {
return idx; }
temp = temp->next;

idx++; }
return -1;



No comments:

Post a Comment

Stack using Linked List – Partial (University Exam Topic)

 #include <iostream> using namespace std; struct Node {     int data;     Node* next; }; class Stack {     Node* top; public:     Stac...