say does anyone out there got a good algorithm for finding the max and min of two numbers here is the code that I have but I cant get the minimum to come out correct.
Code:
#include <iostream>
#include <cstring>
using namespace std;
//linked list first example
struct node
{
int info;
node *next; //a pointer named node of size node(the structure in which it is contained)
};
int main()
{
int d=0, max=0, min=0, counter=0,a[5];
node *list; //a pointer called list of size node
node *p; //a pointer called p of size node
list = new(node); //have list point to a new address
p=list; //make both of those adresses the same
for(int i=0; i<5; ++i)
{
cout<<"Enter the value of this node: "<<endl;
cin>>p->info;//enter a value for the first
d=d+p->info;
a[i]=p->info;
counter++;
if(p->info> max)
{
max=p->info;
}
if(p->info<max)
min=p->info;
p->next=new(node);
p=p->next;
//this one works for sure
}
cout<<"THIS IS THE MAXIMUM NUMBER "<<max<<endl;
cout<<"THE AVERAGE IS: "<<d/counter<<endl;
cout<<"THE NUMBER OF VARIABLES IN THIS LINKED LIST IS "<<counter<<endl;
cout<<"THE MINIMUM IS "<<min<<endl;
cout<<list->info<<" "<<list->next->info<<" "<<list->next->next->info<<" "<<list->next->next->next->info
<<" "<<list->next->next->next->next->info<<" "<<endl;
return 0;
}