//this program will traverse all the data and print them.
//language=C
#include<stdio.h>
#include<stdlib.h>
struct linked_lists{
int data;
struct linked_lists *next;
};
typedef struct linked_lists node;
//this will change the name to node
void create_list(node *p);
//list will be created using this function
void traverse(node *p);
int main(){
node *head;
head=(node*)malloc(sizeof(node));
create_list(head);
traverse(head);
return 0;
}
void create_list(node *p){
char c;
scanf("%d%c", & p->data ,& c);
if(c=='\n'){
p->next=NULL;
}
else{
p->next=(node*)malloc(sizeof(node));
create_list(p->next);
}
return;
}
void traverse(node *p){
while(p){
if(p==NULL)
break;
printf("%d\n",p->data);
p=p->next;
}
return;
}
//language=C
#include<stdio.h>
#include<stdlib.h>
struct linked_lists{
int data;
struct linked_lists *next;
};
typedef struct linked_lists node;
//this will change the name to node
void create_list(node *p);
//list will be created using this function
void traverse(node *p);
int main(){
node *head;
head=(node*)malloc(sizeof(node));
create_list(head);
traverse(head);
return 0;
}
void create_list(node *p){
char c;
scanf("%d%c", & p->data ,& c);
if(c=='\n'){
p->next=NULL;
}
else{
p->next=(node*)malloc(sizeof(node));
create_list(p->next);
}
return;
}
void traverse(node *p){
while(p){
if(p==NULL)
break;
printf("%d\n",p->data);
p=p->next;
}
return;
}
No comments:
Post a Comment