0 / 0 / 0
Регистрация: 14.02.2012
Сообщений: 11
1

Динамические структуры данных, списковые структуры (надо разобраться что делает программа)

13.11.2012, 22:12. Показов 1663. Ответов 2
Метки нет (Все метки)

Author24 — интернет-сервис помощи студентам
дана программа, надо помочь выяснить что в ней делает каждая подпрограмма


Delphi
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
unit Unit6;
 
interface
 
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;
 
type
  TMainForm = class(TForm)
    Button1: TButton;
    GroupBox2: TGroupBox;
    Memo2: TMemo;
    GroupBox3: TGroupBox;
    Memo3: TMemo;
    GroupBox4: TGroupBox;
    Memo4: TMemo;
    OpenDialog1: TOpenDialog;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;
type
  Ptr = ^rec;
  rec = record
    key,key1  : integer;
    next : ptr;
end;
  Queue=record
  head,tail:Ptr;
end;
 
var
  MainForm: TMainForm;
  t:rec;
 
implementation
 
{$R *.dfm}
 
procedure InQueue(var aQueue:Queue; var aPElem:Ptr);
begin
  if aPElem=nil then Exit;
  aPElem^.Next:=nil;
  With aQueue do begin
    if head=nil then head:=aPElem
    else tail^.next:=aPElem;
    tail:=aPElem;
  end;
end;
 
function PQueue(var aQueue:Queue; var aPElem:Ptr):Boolean;
begin
  Result:=False;
  if aQueue.head=nil then Exit;
  With aQueue do begin
    aPElem:=head;
    head:=aPElem^.Next;
    if head=nil then tail:=nil;
    Result:=True;
  end;
end;
 
procedure TMainForm.Button1Click(Sender: TObject);
var
  Top1,Top2,Top3 : Queue;
  PElem1,PElem2,pe1,pe2  : Ptr;
  i,a,b,ind      : Integer;
  s,inputS       : string;
  f              : TextFile;
  Flag           : boolean;
begin
  memo2.Clear;
  memo3.Clear;
  memo4.Clear;
  AssignFile(f,'ќчередь.txt');
  reset(f);
  With Top1 do begin
    head:=nil;
    tail:=nil;
  end;
  With Top2 do begin
    head:=nil;
    tail:=nil;
  end;
  With Top3 do begin
    head:=nil;
    tail:=nil;
  end;
  Flag:=True;
  While Not eof(f) do begin
    Readln(f,s);
    Repeat
      New(PElem1);
      ind:=Pos(',',s);
      a:=StrToInt(Copy(s,1,ind-1));
      Delete(s,1,ind);
      ind:=Pos(';',s);
      If ind=0 then ind:=Pos('|',s);
      b:=StrToInt(Copy(s,1,ind-1));
      Delete(s,1,ind);
      PElem1^.key:=a;
      PElem1^.key1:=b;
      If Flag=True then InQueue(top1,PElem1)
      else InQueue(top2,PElem1)
    until s='';
    Flag:=False;
  end;
  While PQueue(Top1,PElem1) do begin
    inputS:=IntToStr(PElem1.key);
    If s<>'' then
      If InputS[1]<>'-' then s:=s+'+'+inputS+'*x^'+IntToStr(PElem1.key1)
      else s:=s+inputS+'*x^'+IntToStr(PElem1.key1)
    else s:=InputS+'*x^'+IntToStr(PElem1.key1);
  end;
  memo2.Lines.Add(s);
  s:='';
  While PQueue(Top2,PElem1) do begin
    inputS:=IntToStr(PElem1.key);
    If s<>'' then
      If InputS[1]<>'-' then s:=s+'+'+inputS+'*x^'+IntToStr(PElem1.key1)
      else s:=s+inputS+'*x^'+IntToStr(PElem1.key1)
    else s:=InputS+'*x^'+IntToStr(PElem1.key1);
  end;
  memo3.Lines.Add(s);
  s:='';
  closeFile(f);
  Flag:=False;
  Repeat
    New(PE1);
    New(PE2);
    If not PQueue(Top1,PE1) then flag:=True;
    If not PQueue(Top2,PE2) then flag:=True;
    PQueue(Top1,PE1);
    PQueue(Top2,PE2);
    If pe1.key1<Pe2.key1 then begin
      InQueue(Top3,pe1);
      InQueue(Top3,pe2);
    end
    else begin
      InQueue(Top3,pe2);
      InQueue(Top3,pe1);
    end;
    If pe1.key1=Pe2.key1 then begin
      pe1.key:=pe1.key+pe2.key;
      InQueue(Top3,Pe1);
    end;
  until Flag=True;;
  While PQueue(Top3,PElem1) do begin
    inputS:=IntToStr(PElem1.key);
    If s<>'' then
      If InputS[1]<>'-' then s:=s+'+'+inputS+'*x^'+IntToStr(PElem1.key1)
      else s:=s+inputS+'*x^'+IntToStr(PElem1.key1)
    else s:=InputS+'*x^'+IntToStr(PElem1.key1);
  end;
  memo4.Lines.Add(s);
end;
 
end.
0
Programming
Эксперт
94731 / 64177 / 26122
Регистрация: 12.04.2006
Сообщений: 116,782
13.11.2012, 22:12
Ответы с готовыми решениями:

Динамические структуры данных. Организация данных в списковые структуры
Написать программу, формирующую два списка, заполняя их числами из файлов. Объединить оба списка в...

Динамические структуры данных. Организация данных в списковые структуры
Написать программу вставки нового элемента в список за некоторым заданным по- рядковым номером...

Динамические структуры данных. Надо найти причину ошибки программа не запускается
(&quot;Считалка&quot;) n ребят располагаются по кругу. Начав отсчет от первого, удаляют каждого k-го,...

Динамические структуры данных. Программа ввода в структуры и вывода информации из неё.
Автоматизированная информационная система на железнодорожном вокзале содержит сведения об...

2
4 / 4 / 1
Регистрация: 09.02.2012
Сообщений: 65
13.11.2012, 22:23 2
скинь архив с прогой мне на ящик zhdanovich.dmitrii@mail.ru
1
2664 / 2270 / 279
Регистрация: 24.12.2010
Сообщений: 13,723
13.11.2012, 22:27 3
Цитата Сообщение от 4Alex4 Посмотреть сообщение
что в ней делает каждая подпрограмма
InQueue - постановка элемента в хвост очереди.
PQueue - удаление элемента из головы очереди
1
13.11.2012, 22:27
IT_Exp
Эксперт
87844 / 49110 / 22898
Регистрация: 17.06.2006
Сообщений: 92,604
13.11.2012, 22:27
Помогаю со студенческими работами здесь

Программа на использование указателей. Динамические структуры данных
добрый день! помогите пож-та разобраться с задачкой! на какую тему указано выше. как начать...

Списковые структуры. Удаление
Прога, осуществляющая удаление символов из строки вещественного числа. Делал по методичке, но там...

списковые структуры (снова про ферьзей)
С помощью предиката queens 3-х аргументов, найдите все правильные расстановки ферзей на шахматной ...

Динамические структуры данных
Пиплы, нужна помощь. Желательно, чтобы было на Eclipse. Дек содержит последовательность символов...


Искать еще темы с ответами

Или воспользуйтесь поиском по форуму:
3
Ответ Создать тему
Опции темы

КиберФорум - форум программистов, компьютерный форум, программирование
Powered by vBulletin
Copyright ©2000 - 2024, CyberForum.ru