Data Structure
  • টাইম এন্ড স্পেস কমপ্লেক্সিটি
    • সূচনা
    • টাইম কমপ্লেক্সিটি
    • O(N) টাইম কমপ্লেক্সিটি
    • O(logN) টাইম কমপ্লেক্সিটি
    • O(sqrt(N)) টাইম কমপ্লেক্সিটি
    • টাইম কমপ্লেক্সিটির কিছু উদাহরন
    • টাইম কমপ্লেক্সিটি থেকে টাইম ক্যালকুলেট করা
    • স্পেস কমপ্লেক্সিটি
  • মডিউল ২ঃ STL Vector
    • ২-০ঃ সূচনা
    • ২-১ঃ ভেক্টর ইনিশিয়ালাইজেশন এবং কন্সট্রাক্টর
    • ২-২ঃ ভেক্টর ক্যাপাসিটি ফাংশন
    • ২-৩ঃ ভেক্টর মডিফাইয়ার ফাংশন -১
    • ২-৪ঃ ভেক্টর মডিফাইয়ার ফাংশন -২
    • ২-৫ঃ ভেক্টর এক্সেস এবং ইটারেটর
    • ২-৬ঃ ভেক্টরে ইনপুট নেয়া
    • ২-৭ঃ স্ট্রিং এর ভেক্টর
  • Prefix Sum and Binary Search
    • সূচনা
    • Range Sum Query (Codeforces)
    • Prefix Sum পরিচিতি
    • Prefix sum ইমপ্লিমেন্টেশন
    • Binary Search (Codeforces)
    • বাইনারি সার্চ পরিচিতি
    • বাইনারি সার্চ ইমপ্লিমেন্টেশন
  • মডিউল ৫ঃ Singly Linked List
    • ৫-০ঃ সূচনা
    • ৫-১ঃ Linked List কেন?
    • ৫-২ঃ Linked List কেন? (পার্ট ২)
    • ৫-৩ঃ Create a Node
    • ৫-৪ঃ Constructor of Node
    • ৫-৫ঃ Dynamic Node
    • ৫-৬ঃ Singly Linked List কিভাবে তৈরি হয়
    • ৫-৭ঃ Printing Singly Linked List
    • ৫-৮ঃ Printing Singly Linked List (Animated)
  • মডিউল ৬ঃ Singly Linked List Operation
    • ৬-০ঃ সূচনা
    • ৬-১ঃ পয়েন্টারের রেফারেন্স
    • ৬-২ঃ Tail এ ভ্যালু Insertion
    • ৬-৩ঃ যেকোন পজিশনে ভ্যালু Insertion
    • ৬-৪ঃ Head এ ভ্যালু Insertion
    • ৬-৫ঃ যেকোন পজিশনের ভ্যালু Deletion
    • ৬-৬ঃ Head ডিলিট
    • ৬-৭ঃ Error Handling
    • ৬-৮ঃ Singly Linked List এ ইনপুট
  • মডিউল ৭ঃ Singly Linked List recap
    • ৭-০ঃ সূচনা
    • ৭-১ঃ Singly Linked List recap
    • ৭-২ঃ Insert at Singly Linked List Recap
    • ৭-৩ঃ Insert at Head and Tail at Singly Linked List Recap
    • ৭-৪ঃ Delete from Singly Linked List Recap
    • ৭-৫ঃ Delete Head from Singly Linked List Recap
    • ৭-৬ঃ Take Singly Linked List Input Recap
    • ৭-৭ঃ Printing Singly Linked List in Reverse
    • ৭-৮ঃ Sort Singly Linked List
    • ৭-বোনাসঃ Singly Linked list all operations complexity analysis
  • মডিউল ৯: Doubly Linked List
    • ৯-০ঃ সূচনা
    • ৯ -১ঃ Doubly Linked List
    • ৯-২ঃ Doubly Linked List দেখতে কেমন?
    • ৯-৩ঃ Doubly Linked List এর যেকোনো position এ value insert
    • ৯-৪ঃ Insert at Head and Tail in Doubly Linked List
    • ৯-৫ঃ Insert Operation on Doubly Linked List Animated
    • ৯-৬ঃ Delete Operations on Doubly Linked List
    • ৯-৭ঃ Complexity Analysis
    • মডিউল ৯-৮ঃ Doubly Linked List এ input নেয়া
  • মডিউল ১০: STL List and Cycle Detection
    • ১০-০ঃ সূচনা
    • ১০-১ঃ List Constructors
    • ১০-২ঃ List Capacity Functions
    • ১০-৩ঃ List Modifiers Functions
    • ১০-৪ঃ List Operations and Access Related Function
    • ১০-৫ , ১০-৬ঃ Reverse a Singly Linked List
    • ১০-৭ঃ Reverse a Doubly Linked List
    • ১০-৮ঃ Detect Cycle in Singly Linked List
  • মডিউল ১১ঃ Problem Solving using Linked list
    • মডিউল ১১-০ঃ সূচনা
    • মডিউল ১১-১ঃ Middle of the Linked List
    • মডিউল ১১-২ঃ Linked List Cycle
    • মডিউল ১১-৩ঃ Remove Duplicate from Sorted List
    • মডিউল ১১-৪ঃ Reverse Linked List
    • মডিউল ১১-৫ঃ Palindrome Linked List
    • মডিউল ১১-৬ঃ Delete Node in a Linked List
  • Module 13: Stack Implementation and STL
    • মডিউল ১৩-০ঃ সূচনা
    • মডিউল ১৩-১ঃ What is stack (animation)
    • মডিউল ১৩-২,৩ঃ What is stack
    • মডিউল ১৩- ৪,৫ঃ Stack Implement using Array
    • মডিউল ১৩-৬ঃ Stack Implement using List
    • মডিউল ১৩-৭ঃ Stack Implement using Doubly Linked List
    • মডিউল ১৩-৮ঃ STL Stack
  • মডিউল ১৪ঃ Queue Implmentation and STL
    • ১৪-০ঃ সূচনা
    • ১৪-১,১৪-২ঃ Queue কী এবং Queue এর কিছু বাস্তব উদাহরণ
    • ১৪-৩ঃ Singly Linked List এর সাহায্যে Queue তৈরি করা
    • ১৪-৪ঃ Doubly Linked List এর সাহায্যে Queue তৈরি করা
    • ১৪-৫ঃ STL List এর সাহায্যে Queue তৈরি করা
    • ১৪-৬ঃ Queue এর STL লাইব্রেরি
    • ১৪-৭ঃImplement Stack using Queue (Leetcode)
    • ১৪-৮ঃ Implement Queue using Stacks (Leetcode)
  • মডিউল ১৫ঃ Problem Solving using Stack & Queue
    • মডিউল ১৫-০ঃ সূচনা
    • মডিউল ১৫-১ঃ Valid Parentheses (Leetcode)
    • মডিউল ১৫-২ঃ Backspace String Compare (Leetcode)
    • মডিউল ১৫-৩ঃ Insert Element At Bottom of Stack (CodingNinjas)
    • মডিউল ১৫-৪ঃ Maximum Equal Stack Sum (CodingNinjas)
    • মডিউল ১৫-৫ঃ Reversing a Queue (CodingNinjas)
    • মডিউল ১৫-৬ঃ Reverse Stack Using Recursion (CodingNinjas)
  • মডিউল ১৭: Binary Tree Implementation
    • মডিউল ১৭-০ঃ সূচনা
    • মডিউল ১৭-১ঃ Discussion about Tree Data Structure
    • মডিউল ১৭-৩ঃ Discussion about Binary Tree
    • মডিউল ১৭- ৪ঃ Create a Binary Tree
    • মডিউল ১৭-৫ঃ Pre Order Traversal of Binary Tree
    • মডিউল ১৭-৭ঃ Post Order Traversal of Binary Tree
    • মডিউল ১৭-৮ঃ In Order Traversal of Binary Tree
  • মডিউল ১৮ঃ Operations On Binary Tree
    • ১৮-০ঃ সূচনা
    • ১৮-১ঃ Level Order Traversal of Binary Tree থিওরি
    • ১৮-২ঃ Level Order Traversal of Binary Tree ইমপ্লিমেন্টেশন
    • ১৮-৩ঃ Binary Tree Input থিওরি
    • ১৮-৪ঃ Binary Tree Input ইমপ্লিমেন্টেশন
    • ১৮-৫ঃ Count Number of Nodes of a Binary Tree
    • ১৮-৬ঃ Count Number of Leaf Nodes of a Binary Tree
    • মডিউল ১৮-৭ঃGet the Maximum Height of a Binary Tree
  • মডিউল ১৯ঃ Problem Solving using Binary Tree
    • মডিউল ১৯-০ঃ সূচনা
    • মডিউল ১৯-১ঃ Is Node Present (Coding Ninjas)
    • মডিউল ১৯-২ঃ STL Pair, Node Level (Coding Ninjas)
    • মডিউল ১৯-৩ঃ Left View Of a Binary Tree (Coding Ninjas)
    • মডিউল ১৯-৪ঃ Diameter Of Binary Tree (Coding Ninjas)
    • মডিউল ১৯-৫ঃ Special Binary Tree (Coding Ninjas)
    • মডিউল ১৯-৬ঃ Reverse Level Order Traversal (Coding Ninjas)
  • মডিউল ২১ঃ Binary Search Tree Implementation
    • মডিউল ২১-০ঃ সূচনা
    • মডিউল ১৭-১ঃ What is BST
    • মডিউল ২১-২ঃ How to Handle Duplicate in BST
    • মডিউল ২১-৩ঃ Search in BST
    • মডিউল ২১-৫ঃ Insert in BST
    • মডিউল ২১-৭ঃ Convert Array to BST
  • মডিউল ২২ঃ Heap Implmentation
    • ২২-০ঃ সূচনা
    • ২২-১ঃ Complete Binary Tree কী
    • ২২-২ঃ Complete Binary Tree এর Array Representation
    • ২২-৩ঃ Heap কী
    • ২২-৪ঃ Heap এ Insertion এর থিওরি
    • ২২-৫ঃ Heap এ Insertion ইমপ্লিমেন্টেশন
    • ২২-৬ঃ Heap এ Deletion থিওরি
    • ২২-৭ঃ Heap এ Deletion ইমপ্লিমেন্টেশন
  • মডিউল ২৩ঃ STL Priority Queue, Map and Set
    • মডিউল ২৩-০ঃ সূচনা
    • মডিউল ২৩-১ঃ Priority Queue কি?
    • মডিউল ২৩-২ঃ কিভাবে STL Priority Queue কাজ করে
    • মডিউল ২৩-৩ঃ Custom Compare Class for Priority Queue
    • মডিউল ২৩-৪ঃ map কি?
    • মডিউল ২৩-৫ঃ কিভাবে STL map কাজ করে
    • মডিউল ২৩-৬ঃ Count Words in a String using Map
    • মডিউল ২৩-৭ঃ কিভাবে STL set কাজ করে
Powered by GitBook
On this page
  1. মডিউল ৬ঃ Singly Linked List Operation

৬-৭ঃ Error Handling

এই মডিউলে আমারা দেখবো কীভাবে কোনো একটি Invalid ইনপুটের জন্য আমাদের কোড যাতে Crash না করে ঐ পদক্ষেপ গুলা নেয়া যায়। Error 1 : Insert At Any Position এ এমন একটি পজিশন এ Node এড করতে চাওয়া যেখানে Node insert করা যাবে না। যেমনঃ 3 সাইজের একটি Linked list এর ১০ তম পজিশনে Node Insert করা। এই ক্ষেত্রে segmentation fault হয়ে আমাদের crash হয়ে যায়।

Handling : এই ক্ষেত্রে আমরা যদি দেখি Temp shift হতে হতে এক সময় Null এ চলে গেছে অর্থাৎ Invalid index এ চলে যায় , আমরা ঐখানে লুপ থামিয়ে দিয়ে Invalid index বলে দিবো।

void insert_at_position(Node *&head, int index, int value)
{

    Node *newNode = new Node(value); // নতুন Node বানিয়ে নিলাম 

    Node *temp = head; // temp পয়েন্টার এ head রেখে দিলাম 

    for (int i = 1; i <= index - 1; i++)
    {
        temp = temp->next;
        if(temp==NULL){
        cout << "Invalid Index" << endl ;
        return ; // এখানে ফাংশন থামিয়ে দিবো , কারণ এই Invalid index নিয়ে কোনো কাজ করা যাবে না
       } 
    }
   
    newNode->next = temp->next; 
    temp->next = newNode; 
}

Error 2 : Delete At Any Position এ এমন একটি পজিশন এ Node Delete করতে চাওয়া যেখানে কোনো Node ই নেই। যেমনঃ 3 সাইজের একটি Linked list এর ১০ তম পজিশনে Node delete করা। এই ক্ষেত্রে segmentation fault হয়ে আমাদের crash হয়ে যায়। ঠিক আগের প্রবলেমের মতো। তা ছাড়া ও আমরা লুপ শেষ হয়ে যদি শেষ Index এ চলে আসি , এবং এই Node এর সাথে Next index কানেক্ট করতে চাই , তবে সেখানে কোনো Node থাকবে না , কারণ আমি already শেষ Node এই আছি। এটিও segmentation fault আসবে।

Handling : আগের মতো এই ক্ষেত্রে আমরা যদি দেখি Temp shift হতে হতে এক সময় Null এ চলে গেছে অর্থাৎ Invalid index এ চলে যায় , আমরা ঐখানে লুপ থামিয়ে দিয়ে Invalid index বলে দিবো। দ্বিতীয় ইরর এর জন্য আমরা চেক করে দেখবো temp node এর next এর next এ NULL আছে কিনা। NULL থাকলে এটি Invalid index.

void delete_at_position(Node *&head, int position)
{

    Node *temp = head;

    for (int i = 1; i <= position - 1; i++) 
    {
        temp = temp->next;
         if(temp==NULL){
        cout << "Invalid Index" << endl ;
        return ; // এখানে ফাংশন থামিয়ে দিবো , কারণ এই Invalid index নিয়ে কোনো কাজ করা যাবে না
       } 
    }
     if(temp->next==NULL){ // দ্বিতীয় error টি handle করা হচ্ছে। 
        cout << "Invalid Index" << endl ;
        return ; // এখানে ফাংশন থামিয়ে দিবো , কারণ এই Invalid index নিয়ে কোনো কাজ করা যাবে না
       } 
    Node* delete_node = temp->next;  
    temp->next = temp->next->next;  
    delete delete_node; 
}

Error 3: Delete head এর ক্ষেত্রে LInkded List যদি খালি হয়ে থাকে , তবে সেই ক্ষেত্রে head delete করলে segmentation fault হবে।

Handling : এই ক্ষেত্রে আমরা যদি দেখি head নেই /Null. অর্থাৎ লিঙ্কড লিস্ট খালি , তবে সেইক্ষেত্রে Invalid Index প্রিন্ট করে ফাংশন অফ করে দিবো।

void delete_head(Node *&head){

   if(head == NULL) { //  লিঙ্কড লিস্ট খালি
      cout << "Linked List is empty" << endl ;
        return ;
    }
   
    Node* delete_node = head; // Delete_node এ head কে স্টোর করে রাখলাম
    head = head->next; //head এ head->next স্টোর করে রাখি 
    delete delete_node; // delete_node কে delete করে দিলাম 
}
Previous৬-৬ঃ Head ডিলিটNext৬-৮ঃ Singly Linked List এ ইনপুট

Last updated 10 months ago