এই সমস্যায়, আমাদের একটি দ্বিগুণ লিঙ্কযুক্ত তালিকা দেওয়া হয়েছে LL. আমাদের কাজ হল Dubly Linked List-এ সবচেয়ে বড় নোড খুঁজে পাওয়া .
সমস্যাটি বোঝার জন্য একটি উদাহরণ নেওয়া যাক,
Input : linked-list = 5 -> 2 -> 9 -> 8 -> 1 -> 3 Output : 9
সমাধান পদ্ধতি
সমস্যা সমাধানের একটি সহজ পদ্ধতি হল লিঙ্কড-তালিকা অতিক্রম করে এবং যদি ম্যাক্স-এর ডেটা মান maxVal-এর ডেটার চেয়ে বেশি হয়। লিঙ্ক করা-তালিকা অতিক্রম করার পরে, আমরা ম্যাকভাল নোড ডেটা ফেরত দেব।
উদাহরণ
আমাদের সমাধানের কাজ চিত্রিত করার জন্য প্রোগ্রাম
#include <iostream>
using namespace std;
struct Node{
int data;
struct Node* next;
struct Node* prev;
};
void push(struct Node** head_ref, int new_data){
struct Node* new_node = (struct Node*)malloc(sizeof(struct Node));
new_node->data = new_data;
new_node->prev = NULL;
new_node->next = (*head_ref);
if ((*head_ref) != NULL)
(*head_ref)->prev = new_node;
(*head_ref) = new_node;
}
int findLargestNodeInDLL(struct Node** head_ref){
struct Node *maxVal, *curr;
maxVal = curr = *head_ref;
while (curr != NULL){
if (curr->data > maxVal->data)
maxVal = curr;
curr = curr->next;
}
return maxVal->data;
}
int main(){
struct Node* head = NULL;
push(&head, 5);
push(&head, 2);
push(&head, 9);
push(&head, 1);
push(&head, 3);
cout<<"The largest node in doubly linked-list is "<<findLargestNodeInDLL(&head);
return 0;
} আউটপুট
The largest node in doubly linked-list is 9