Why it's printint position doesn't exist everytime and also it's not printing the 3rd data?

0 votes
asked Oct 4, 2018 by Amey Bikram (120 points)
#include <iostream>

using namespace std;

struct dllnode
    int data;
    dllnode *next,*prev;
class dlinked_list
    dllnode *head,*tail;
    void insertionindll(int ,int);
    static void display(dllnode *);
    dllnode* gethead()
        return head;
    dllnode* create_node(int data);
dllnode* dlinked_list::create_node(int n)
    dllnode *temp=new dllnode;
    return temp;
void dlinked_list::insertionindll(int n, int pos)
    dllnode *temp;
    int k=1;
    dllnode *newnode= create_node(n);
        cout<<"Memory Error";    //Checking memory error
    if(pos==1)    //Insertion at the beginning//
    //After this loop temp will either point to the last node
    //or the previous node at which we want to insert newnode
    while(k<pos && temp->next!=NULL)
        cout<<"position doesn't exist"<<endl;
void dlinked_list::display(dllnode *a)
    dllnode *ptr;
int main()
    /* code */
    dlinked_list a;
    return 0;

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please log in or register.
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.