Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<malloc.h>
- #include<iostream>
- using namespace std;
- struct node
- {
- char info[10];
- struct node *link;
- } *start=NULL;
- int main()
- {
- int size;
- struct node *ptr;
- cout<<"size of the list:";
- cin>>size;
- if(start==NULL)
- {
- start = (struct node *)malloc(sizeof(struct node));
- cin>>start->info;
- start->link=NULL;
- }
- ptr=start;
- for(int i=0;i<size-1;i++)
- {
- ptr->link=(struct node *)malloc(sizeof(struct node));
- ptr=ptr->link;
- cin>>ptr->info;
- ptr->link=NULL;
- }
- cout<<"the list is:\n";
- ptr=start;
- for(int i=0;i<size;i++)
- {
- cout<<ptr->info<<endl;
- ptr=ptr->link;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment