05.11.2010, 03:14. Просмотров 1711. Ответов 4
Вот сделал лабу и все работает отлично, но осталось последнее new выделяет память мне нужно
добавить функцию которая будет вызыватся в конце и чистить память но как это сделать хз пробовал не получилось((
C++ |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
| #include <iostream>
#include <cstdlib>
#include <fstream>
#include<clocale>
using namespace std;
struct LIST {
int info;
LIST *next;
};
int proverka(LIST *head,int h, int x0,int s)
{ int c=0;
int tmp=x0;
LIST *p = head;
for(int i=0;i<s;i++)
{
if(p->info != tmp)
{c=0;
return c;
}
else
{
c++;
p=p->next;
tmp=tmp+h;
}
}
return c;
}
int add(fstream &fin,LIST *p)
{int prov=0;
while( !fin.eof() )
{
fin >> p->info;
p->next =new LIST;
p=p->next;
prov++;
}
return prov;
}
int main()
{ setlocale(LC_ALL, "rus");
int h,s;
int x0;
fstream fin;
LIST *head;
head = new LIST;
LIST* p = head;
fin.open("fin.txt",ios_base::in);
if(fin.is_open()==false)
cout << "ошибка открытия fin.txt!!!";
cout << "Введите начальное значение:" << endl;
cin >> x0;
cout << "Введите шаг:" << endl;
cin >> h;
s=add(fin,p);
if (s == proverka(head,h,x0,s))
cout << "podxodit";
else
cout << "ne podxodit";
return 0;
} |
|
Добавлено через 27 минут
C++ |
1
2
3
4
5
6
7
8
9
10
11
| void del(LIST *head,int s)
{int i;
LIST *tmp=head;
while ( head )
{
tmp = head->next;
delete head;
head = tmp;
}
} |
|
сделал такую функцию но программа завернает работу ....