Computer Science, asked by ilovecats7706, 7 hours ago

Write an algorithm to create a singly linked list to store the elements 2,4,2,6,7 and 11 in that order.​

Answers

Answered by divyanshdubey818
0

AnswersAttention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.In case you wish to attend live classes with experts, please refer DSA Live Classes for Working Professionals and Competitive Programming Live for Students.

Answered by NehaKari
1

Answer:

Explanation:#include <stdio.h>

#include <stdlib.h>

struct Node

{

   int data;

   struct Node * next;

};

void listTraversal(struct Node *ptr)

{

   while (ptr!= NULL)

   {

       printf("Element: %d\n", ptr->data);

       ptr = ptr->next;

   }

}

int main()

{

   struct Node *head;

   struct Node *second;

   struct Node *third;

   struct Node *fourth;

   struct Node *fifth;

   struct Node *sixth;

   head = (struct Node *)malloc(sizeof(struct Node));

   second = (struct Node *)malloc(sizeof(struct Node));

   third = (struct Node *)malloc(sizeof(struct Node));

   fourth = (struct Node *)malloc(sizeof(struct Node));

    fifth = (struct Node *)malloc(sizeof(struct Node));

    sixth = (struct Node *)malloc(sizeof(struct Node));

   head->data = 2;

   head->next = second;

   second->data = 4;

   second->next = third;

   third->data = 2;

   third->next = fourth;

   fourth->data = 6;

   fourth->next = NULL;

   listTraversal(head);

   return 0;

}

Similar questions