Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<stdlib.h>
- struct node{
- int data;
- struct node *link;
- };
- struct node *head=NULL;
- struct node *tail=NULL;
- main(){
- int x,i;
- scanf("%d",&x);
- for(i=0;i<x;i++){
- int value;
- scanf("%d",&value);
- struct node *NODE=(struct node*)malloc(sizeof(struct node));
- NODE->data=value;
- NODE->link=NULL;
- if(head==NULL){
- head=NODE;
- tail=NODE;
- }else{
- tail->link=NODE;
- tail=NODE;
- }
- }
- struct node *pt=head;
- int count=0;
- while(pt->link != NULL|| count==0){
- if(pt->link == NULL){
- printf("%d ",pt->data);
- count++;
- break;
- }else{
- printf("%d ",pt->data);
- pt=pt->link;
- }
- }
- struct node *ptr=head;
- struct node *temp;
- int k=0;
- while(ptr->link != NULL){
- k++;
- if(k==3){
- break;
- }else{
- temp=ptr;
- ptr=ptr->link;
- }
- }
- temp->link=ptr->link;
- free(ptr);
- // struct node *NODE=(struct node*)malloc(sizeof(struct node));
- // NODE->data=100;
- // NODE->link=NULL;
- // NODE->link=ptr->link;
- // ptr->link=NODE;
- struct node *ptt=head;
- int countt=0;
- printf("\n");
- while(ptt->link != NULL|| countt==0){
- if(ptt->link == NULL){
- printf("%d ",ptt->data);
- count++;
- break;
- }else{
- printf("%d ",ptt->data);
- ptt=ptt->link;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement