Skip to content

Instantly share code, notes, and snippets.

@ehzawad
Created March 28, 2016 07:28
Show Gist options
  • Select an option

  • Save ehzawad/d9178c214924f70afb4c to your computer and use it in GitHub Desktop.

Select an option

Save ehzawad/d9178c214924f70afb4c to your computer and use it in GitHub Desktop.
#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