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 recap

৭-৬ঃ Take Singly Linked List Input Recap

এবার আমরা লিঙ্কড লিস্টে ইনপুট নেওয়া রিকেপ করব।

লিঙ্কড লিস্টের ইনপুট নরমালি -1 দিয়ে টারমিনেট করা হয়। আমরা ইনপুট ভেলু নিয়ে তা দিয়ে নোড ক্রিয়েট করে লিঙ্কড লিস্টে ইনসার্ট করতে থাকব যতক্ষন না আমরা ইনপুটে -1 পাচ্ছি। আগের মডিউলে আমরা ইনসার্ট টেলে করতাম এবং সেটার কমপ্লেক্সিটি ছিল 0(N)। এই মডিউলে আমরা অপ্টিমাইজ ওয়ে শিখেছি। আমরা দেখেছি টেল ট্র্যাক রেখে টেলে ইনসার্ট করলে O(1) কমপ্লেক্সিটিতে করা যায়। তাই এবার আমরা তাই করব। এক্ষেত্রে 1 টি ভেলু ইনসার্ট করার কমপ্লেক্সিটি হবে O(1) এবং N টি ভেলু ইনসার্ট করার কমপ্লেক্সিটি হবে O(N)

#include <bits/stdc++.h>
using namespace std;
class Node
{
public:
    int val;
    Node *next;
    Node(int val)
    {
        this->val = val;
        this->next = NULL;
    }
};
void insert_tail(Node *&head, Node *&tail, int val)
{
    Node *newNode = new Node(val);     // টেল ট্র্যাক রেখে ইনসার্ট করা হচ্ছে, যার কমপ্লেক্সিটি O(1)
    if (head == NULL)
    {
        head = newNode;
        tail = newNode;
        return;
    }
    tail->next = newNode;
    tail = newNode;
}
void print_linekd_list(Node *head)
{
    Node *tmp = head;
    while (tmp != NULL)
    {
        cout << tmp->val << " ";
        tmp = tmp->next;
    }
    cout << endl;
}
int main()
{
    Node *head = NULL;
    Node *tail = NULL;
    int val;
    while (true)
    {
        cin >> val;         // ভেলু ইনপুট নিচ্ছি। 
        if (val == -1)      // ভেলুটি -1 হলে ব্রেক করে দিচ্ছি। 
            break;
        insert_tail(head, tail, val);    // ইনসার্ট টেল ফাংশনকে কল করে টেলে ইনসার্ট করা হচ্ছে।
    }
    print_linekd_list(head);
    return 0;
}

Previous৭-৫ঃ Delete Head from Singly Linked List RecapNext৭-৭ঃ Printing Singly Linked List in Reverse

Last updated 10 months ago