Facebook
From Harmless Mockingbird, 3 Years ago, written in C++.
This paste is a reply to Untitled from Ivory Anoa - go back
Embed
Viewing differences between Untitled and Re: Untitled
#include 
using namespace std;
struct node

{
int data;
struct node *next;
};

    int main()

{
    struct node *prev,*head,*p;
    head=NULL;
    int n;
    scanf("%d",&n);
    for(int i=0;i     {
        p=(struct node*)malloc(sizeof(struct node));
        scanf("%d",&p->data);
        p->next=NULL;
        if(head==NULL){
        head=p;
    }
    else {
        prev->next=p;
    }
    prev=p;
    }

    int x;
    printf("Enter position: ");
    scanf("%d",&x);

    struct node *ptr=head;
   int i;
   while(ptr!=NULL)
   {
       ++i;
       if(i==x)
       {
         prev->next=ptr->next;
         free(ptr);
         break;
       }
       prev=ptr;
       ptr=ptr->next;
   }



   ptr=head;
   while(ptr!=NULL)
   {
       printf("%d ", ptr->data);
       ptr=ptr->next;
   }
    return 0;
}