Hi all. I'm from Poland so sorry for my English, but I think you'll unterstand my thread.
In the University my teacher wrote the program in Visual Studio, in school this program working, but in the home my teacher saw that this program working not good. We have to find the mistake in the program and send to my teacher the mail with the solution. But we don't know where is the mistake so I must say to You HELP!
This is code this programs
[code]Witam. Od wykładowcy na studiach grupa otrzymała maila postaci:
Code:
// list.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <cstdio>
using namespace std;
struct list_node
{
int number;
list_node *next;
};
void add_element(list_node *list, list_node *current)
{
list_node *node = list->next;
list->next = current;
current->next = node;
}
void remove_element(list_node *list, int number)
{
while(list->next)
{
if(list->next->number == number)
{
list_node *node = list->next;
list->next = list->next->next;
delete node;
}
else
{
list = list->next;
}
}
}
int _tmain(int argc, _TCHAR* argv[])
{
list_node *list = new list_node;
list->number = -1;
list->next = 0;
// dodawanie element�w do listy (sprawdzi�, czy elementy dodawane s� na jej pocz�tek, czy na koniec)
for(int i = 0; i < 10; ++i)
{
list_node *current = new list_node;
current->number = i;
add_element(list, current);
}
// usuwanie element�w z listy o zadanym numerze
int to_delete[] = {7, 0, 1, 9, 5, 5, 3, 145};
for(int i = 0; i < sizeof(to_delete)/sizeof(int); ++i)
{
remove_element(list, to_delete[i]);
}
// wy�wietlenie pozosta�ych element�w listy
while(list)
{
printf("Element nr %i\n", list->number);
list = list->next;
}
return 0;
}
Thanks for your help. Cy'a