Napisałem taki oko program ale w zaznaczonym miejscu zamienia wartości.
Wiecie może gdzie popełniłem błąd? Prawdopodobnie znajduje się on w funkcji give
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
struct open_list
{
double f;
open_list *next;
};
void add_front(open_list *&start,double f)
{
open_list *p=new open_list;
p->f=f;
p->next=start;
start=p;
}
open_list give(open_list *&start)
{
open_list *x=new open_list;
open_list *s=new open_list;
s=start;
x->f=10000;
while(s!=NULL)
{
if(x->f>s->f)
{
x=s;
}
s=s->next;
}
open_list *st=new open_list;
st=start;
while(st!=NULL)
{
if(x==st)
{
st->f=1066;
//w tym miejscu zmienia wartosc x->f z wczesniej otrzymanej na 1066 ktora jest podana linijke wyżej
}
st=st->next;
}
return *x;
}
void show(open_list *&start)
{
if(start!=NULL)
{
cout<<start->f<<endl;
show(start->next);
}
}
int main()
{
srand(time(NULL));
open_list *start=new open_list;
start=NULL;
for(int i=0; i<10; i++)
{
add_front(start, rand()%50);
}
show(start);
open_list *g=new open_list;
*g=give(start);cout<<"xXx "<<g->f<<endl;
show(start);
return 0;
}