Linklist insert
unknown
c_cpp
a year ago
873 B
3
Indexable
Never
#include<stdio.h> #include<stdlib.h> struct node { int data; struct node *link; }; int main() { int n; scanf("%d",&n); struct node *current,*first,*previous; for(int i=0; i<n; i++) { current=malloc(sizeof(struct node)); int x; scanf("%d",¤t->data); if(i==0)first=current; else { previous->link=current; } previous=current; } current->link=NULL; int in; scanf("%d",&in); struct node *p=first,*f,*a; f=malloc(sizeof(struct node)); f->data=25; f->link=NULL; a=first; for(int i=1;i<=in-2;i++){ a=a->link; } f->link=a->link; a->link=f; while(p!=NULL) { printf("%d\n",p->data); p=p->link; } return 0; }