Preview:
void Insert(int pos, int x){
  Node *t, *p;
  if(pos==0){
    t= new Node;
    t->data= x;
    t->next= first;
    first= t;
  }
  else if(pos>0){
    p = first;
    for(i=0; i<pos-1; i++)
      p=p->next;
    if(p){
      t= new Node;
      t->data= x;
      t->next = p->next;
      p->next= t;
    }
  }
}
downloadDownload PNG downloadDownload JPEG downloadDownload SVG

Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!

Click to optimize width for Twitter