Posts

Showing posts from August, 2020

Complete Doubly linked list using C

#include<stdio.h> #include<conio.h> #include<stdlib.h>   struct node   {       int data;        struct node *next, *prev;   };   struct node *head, *tail, *newnode, *temp;   int count =0;   void create()   {       int choice=1;       while(choice==1){       newnode = (struct node*)malloc(sizeof(struct node));       count++;       newnode->next=0;       newnode->prev=0;       printf("\nenter data: ");       scanf("%d",&newnode->data);       if(head==0)       {           head=newnode;           tail=newnode;       }       else       {           newnode->prev=tail;           tail->next=newnode; ...

Doubly linked list, with Separate functions for each operation Using C

#include<stdio.h> #include<conio.h> #include<stdlib.h>   struct node   {       int data;        struct node *next, *prev;   };   struct node *head, *tail, *newnode, *temp;   int count(int a)   {       static int count ;       count +=a;       return count;   }   void create()   {       int choice=1;       while(choice==1){       newnode = (struct node*)malloc(sizeof(struct node));       count(1);       newnode->next=0;       newnode->prev=0;       printf("\nenter data: ");       scanf("%d",&newnode->data);       if(head==0)       {           head=newnode;           tail=newnode;       }       else   ...

Doubly Linked List Creation and Insertion At Beg, mid, and at end C++

#include<bits/stdc++.h>  using namespace std;   struct node   {       int data;        struct node *next, *prev;   };   struct node *head, *tail, *newnode, *temp;   int count=0;   void create()   {       int choice=1;       while(choice==1){           ::count++;       newnode = (struct node*)malloc(sizeof(struct node));       newnode->next=0;       newnode->prev=0;       cout<<"\nenter data: ";       cin>>newnode->data;       if(head==0)       {           head=newnode;           tail=newnode;       }       else       {           newnode->prev=tail;           tail->next=newnode; ...

Linked list creation, deletion & insertion.

At Beginning, End and middle. #include<bits/stdc++.h>  using namespace std;   struct node  {      int data;      struct node * next;  };  struct node * head, * newnode, *temp;   int main()   {       int choice;       head = 0;       cout<<"do you want to enter data in list(0,1): ";       cin>>choice;       while(choice==1)       {       newnode=(struct node*)malloc(sizeof(struct node));       newnode->next=0;       cout<<" enter data in list";       cin>>newnode->data;       if(head==0)       {           head = newnode;           temp =head;       }       else       {           temp->n...

Pairs

Using Vectors #include<vector> #include<bits/stdc++.h>  using namespace std;   int main()   {       int n,i,a;       cin>>n;       vector< pair<int,int>> v;       for(i=0;i<n;i++)       {           cin>>a;           v.push_back(make_pair(a,i+1));       }       sort(v.begin(),v.end()); //Sorting, but the vector of pairs is sorted according to first value of pair       for(i=0;i<n/2;i++)       {           cout<< v[i].second <<" "<< v[n-1-i].second <<" "<< v[i].first <<endl;       }   } Using Arrays #include <bits/stdc++.h> using namespace std; int main()  { int n;     cin>>n; pair<int,int>a[100]  or a[n];   for...