fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. struct node{
  5. char num; //Data of the node
  6. struct node *nextptr; //Address of the next node
  7. };
  8. typedef struct node element;
  9. typedef element *link;
  10. link head;
  11.  
  12. void displayList(); // function to display the list
  13. link stol(const char s[]){
  14. link head;
  15. if (s[0] == '\0')return(NULL);
  16. else {
  17. head = (link)malloc(sizeof(element));
  18. head->num = s[0];
  19. head->nextptr = stol(s + 1);
  20. return(head);
  21. }
  22. }
  23.  
  24. int main(void){
  25. char s[] = "abc";
  26.  
  27. printf("\n\n Linked List : To create and display Singly Linked List :\n");
  28. printf("-------------------------------------------------------------\n");
  29. head = stol(s);
  30. displayList();
  31. return 0;
  32. }
  33.  
  34. void displayList(){
  35. if (head == NULL){
  36. printf(" List is empty.");
  37. }
  38. else{
  39. link tmp = head;
  40. while (tmp != NULL){
  41. printf(" Data = %d(%c)\n", tmp->num, tmp->num);
  42. tmp = tmp->nextptr;
  43. }
  44. }
  45. }
Success #stdin #stdout 0s 9432KB
stdin
Standard input is empty
stdout

 Linked List : To create and display Singly Linked List :
-------------------------------------------------------------
 Data = 97(a)
 Data = 98(b)
 Data = 99(c)