Untitled

 avatar
unknown
plain_text
2 months ago
682 B
4
Indexable
#include<stdio.h>
#include<stdlib.h>
struct node
{
    int data;
    struct node* next;
};
struct node* head;
void createlist()
{
    struct node* n1,*n2,*n3;
    n1 = (struct node*)malloc(sizeof(struct node));
    n2 = (struct node*)malloc(sizeof(struct node));
    n3 = (struct node*)malloc(sizeof(struct node));
    n1->data = 10;
    n2->data = 20;
    n3->data = 30;

    n1->next = n2;
    n2->next = n3;
    n3->next = NULL;

    head = n1;
}
void display()
{
    struct node* temp = head;
    while(temp != NULL)
    {
        printf("%d ",temp->data);
          temp = temp->next;
    }
}
int main()
{
    createlist();
    display();
}
Editor is loading...
Leave a Comment