Created
March 28, 2016 07:28
-
-
Save ehzawad/d9178c214924f70afb4c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| typedef struct node{ | |
| int data; | |
| struct node* next; | |
| }node; | |
| node* head = NULL; | |
| void insertAtFirst(int value) | |
| { | |
| node* newNode = new (node); | |
| newNode->data = value; | |
| newNode->next = NULL; | |
| if (head != NULL){ | |
| newNode->next = head; | |
| } | |
| head = newNode; | |
| } | |
| void printData(void) | |
| { | |
| node* temp = head; | |
| for (node* counter = temp; counter != NULL; counter = counter->next){ | |
| std::cout << counter->data << " "; | |
| } | |
| } | |
| int findMin(void) | |
| { | |
| if (head != NULL){ | |
| int tempVal; | |
| node* temp = head; | |
| int minimum = temp->data; | |
| for (node* counter = temp; counter != NULL; counter = counter->next){ | |
| if (minimum > counter->data ) | |
| { | |
| tempVal = counter->data; | |
| } | |
| } | |
| return tempVal; | |
| } | |
| } | |
| int main(void) | |
| { | |
| insertAtFirst(7); | |
| insertAtFirst(6); | |
| insertAtFirst(9); | |
| insertAtFirst(1); | |
| insertAtFirst(4); | |
| insertAtFirst(2); | |
| printData(); | |
| std::cout << std::endl; | |
| std::cout << findMin()<< std::endl; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment