Skip to content

Instantly share code, notes, and snippets.

@shaina7837
Created November 13, 2013 15:05
Show Gist options
  • Save shaina7837/7450540 to your computer and use it in GitHub Desktop.
Save shaina7837/7450540 to your computer and use it in GitHub Desktop.
#include <iostream>
using namespace std;
struct linkedlist{
int data;
linkedlist *link;
linkedlist *prev;
};
main(){
linkedlist *first, *sec, *third, *fourth, *fifth, *ptr, *ele, *ptr1;
first = new linkedlist();
first->data = 10;
sec = new linkedlist();
sec->data = 20;
third = new linkedlist();
third->data = 30;
fourth = new linkedlist();
fourth->data = 40;
fifth = new linkedlist();
fifth->data = 50;
ptr = new linkedlist();
first->link = sec;
sec->link = third;
third->link = fourth;
fourth->link = fifth;
fifth->link = NULL;
first->prev =NULL;
sec->prev = first;
third->prev = sec;
fourth->prev = third;
fifth->prev = fourth;
int item, loc;
cout<<"enter the item to be inserted";
cin>>item;
ele = new linkedlist();
ele->data = item;
int k;
for(k=1,ptr = first; ptr!=NULL; k++,ptr=ptr->link)
{if(loc == k){
(ptr->prev)->link = ele;
ele->link = ptr;
}}
for(ptr1 = first; ptr1!=NULL; ptr1=ptr1->link)
{
cout<<endl<<ptr1->data;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment