Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<stdlib.h>
- struct a
- {
- char a;
- int b;
- struct a *p;
- };
- struct a *ptr,*head,*first,*last2;
- int main()
- {
- int i;
- ptr=(struct a*)malloc(sizeof(struct a));
- char k='a';
- int l=1;
- head=ptr;
- for(i=1; i<=26; i++)
- {
- ptr->a=k++;
- ptr->b=l++;
- if(i!=27)
- {
- ptr->p=(struct a*)malloc(sizeof(struct a));
- ptr=ptr->p;
- }
- }
- ptr->p=NULL;
- first=(struct a*)malloc(sizeof(struct a));
- ptr=head;
- head=first;
- first->a='A';
- first->b=96;
- first->p=ptr;
- ptr=head;
- while(ptr->p!=NULL)
- {
- printf("%c ",ptr->a);
- printf("%d\n",ptr->b);
- ptr=ptr->p;
- if(ptr->p==NULL)
- {
- last2=(struct a*)malloc(sizeof(struct a));
- last2->a='H';
- last2->b=102;
- ptr->p=last2;
- ptr=ptr->p;
- printf("%c ",ptr->a);
- printf("%d\n",ptr->b);
- break;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement