fork download
  1. #include <iostream>
  2. #include <bits/stdc++.h>
  3.  
  4. using namespace std;
  5.  
  6.  
  7. struct Node
  8. {
  9. int data;
  10. struct Node* next;
  11. };
  12.  
  13.  
  14. int small(struct Node* head)
  15. {
  16.  
  17. int min = INT_MAX;
  18.  
  19.  
  20. while (head != NULL)
  21. {
  22.  
  23. if ( min > head->data)
  24. min = head->data;
  25.  
  26. head = head->next;
  27. }
  28. return min;
  29. }
  30.  
  31.  
  32.  
  33. void push (struct Node ** head ,int data)
  34. {
  35. struct Node * newNode ;
  36.  
  37. newNode->data=data;
  38.  
  39. newNode->next = (*head);
  40. (*head) = newNode;
  41. }
  42.  
  43.  
  44. void display(struct Node* head)
  45. {
  46. while ( head != NULL )
  47. {
  48. printf("%d -> ", head->data);
  49. head = head->next;
  50.  
  51. }
  52. cout << "NULL" << endl;
  53. }
  54.  
  55. int main()
  56. {
  57. int x;
  58. struct Node* head = NULL;
  59.  
  60.  
  61. push(&head,5);
  62. push(&head,10);
  63. push(&head,19);
  64.  
  65. cout << "Linked list is:"<<endl;
  66.  
  67. display(head);
  68. cout <<"The minimum element in linked list :"<<endl;
  69. cout << small(head) <<endl;
  70.  
  71.  
  72. return 0;
  73. }
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
Linked list is:
NULL
The minimum element in linked list :
2147483647