Posts

Showing posts from November, 2021

nested map and imp ques

  #include <bits/stdc++.h> using namespace std ; #define shailesh ios :: sync_with_stdio ( false ); cin. tie ( 0 ); cout. tie ( 0 ); #define ll long long int #define vi vector < int > #define pii pair < int , int > #define vii vector < pii > #define rep ( i , a , b ) for ( int i = a; i < b; ++ i) #define ff first #define ss second int main (){     shailesh         map < pair < string , string > , vector < int >> m;     int n;    cin >> n;     rep (i, 0 , n){         string fn, ln;         int ct;        cin >> fn >> ln >> ct;         rep (j, 0 , ct){             int x;            cin >> x;            m [ {fn, ln} ] . push_back (x);       ...

vector of vector again stl

  #include <bits/stdc++.h> using namespace std ; #define shailesh ios :: sync_with_stdio ( false ); cin. tie ( 0 ); cout. tie ( 0 ); #define ll long long int #define vi vector < int > #define pii pair < int , int > #define vii vector < pii > #define rep ( i , a , b ) for ( int i = a; i < b; i ++ ) #define ff first #define ss second void printVec ( vector < int > & v ){     cout << "size : " << v . size () << " " << endl ;     for ( int i = 0 ; i < v . size (); i ++ )     {         cout << v [ i ] << " " ;     }     cout << endl ;     } int main (){     shailesh     vector < vector < int >> v;     int N;    cin >> N;     for ( int i = 0 ; i < N; i ++ )    {         int n;      ...

vector of vector(stl)

  #include <bits/stdc++.h> using namespace std ; #define shailesh ios :: sync_with_stdio ( false ); cin. tie ( 0 ); cout. tie ( 0 ); #define ll long long int #define vi vector < int > #define pii pair < int , int > #define vii vector < pii > #define rep ( i , a , b ) for ( int i = a; i < b; i ++ ) #define ff first #define ss second void printVec ( vector < int > & v ){     cout << "size : " << v . size () << " " << endl ;     for ( int i = 0 ; i < v . size (); i ++ )     {         cout << v [ i ] << " " ;     }     cout << endl ;     } int main (){     shailesh     int N;    cin >> N;     vector < int > v[N];     for ( int i = 0 ; i < N; i ++ )    {         int n;        cin ...

linked list imp and rep , traversing, searching , insertion and deletion

#include <iostream> using namespace std ; // searching and traversing in linked list class node {     public:     int data;     node * next;     node ( int val ){         data = val ;         next = NULL ;     } }; // void deleteAtHead(node* &head, int val){ //     node* n=new node(val); //     n->next=head; //     head=n; // } // void insertElement(node* &head, int val){ // } void deleteAtHead ( node * & head ){         node * todelete = head ;     head = head ->next;     delete todelete;     } void deleteElement ( node * & head , int val ){     if ( head == NULL ){         return ;     }     node * temp = head ;     if ( head ->next == NULL ){         deleteAtHead ( head );       ...

Doubly linked list

  #include <iostream> using namespace std ; class node {     public:     int data;     node * next;     node * prev;     node ( int val ){         data = val ;         next = NULL ;         prev = NULL ;     } }; void deleteAtHead ( node * & head ){     node * todelete = head ;     head = head ->next;     head ->prev = NULL ;     delete todelete; } void deletion ( node * & head , int pos ){     if ( pos == 1 ){         deleteAtHead ( head );         return ;     }     node * temp = head ;     int count = 1 ;     while (temp != NULL && count != pos ){         temp = temp->next;         count ++ ;     }     temp->prev->next = t...

priority_queue

  #include <iostream> #include <queue> #include <vector> using namespace std ; int main (){     // priority_queue<int> q;     // priority_queue<int, vector<int>, greater<int>> q;     auto cmp = []( int a , int b ){         return a < b ;     };     priority_queue < int , vector < int > , decltype (cmp) > q(cmp);         vector < int > v = { 8 , 1 , 6 , 4 , 0 , 7 , 2 , 9 };     for ( int x: v) q. push (x);     while ( ! q. empty ()){         cout << q. top () << " " ;         q. pop ();     }     cout << endl ;     return 0 ; }

Circular queue

  #include <iostream> using namespace std ; #define n 20 class queue {     int * arr;     int front;     int back;     public:     queue (){         arr = new int [ n ];         front =- 1 ;         back =- 1 ;     }     bool isFull (){         if ((back + 1 ) % n == front){ return true ;         }         else {             return false ;         }                             }     void push ( int x ){         if ( isFull ()){             cout << "queue is overflow " << endl ;             return ;         }         ba...