Здраствуйте. Имеется код на Pascal:
| Код | type link = ^node; node = record key: integer; st: string; next: link; end;
var mas: array[0..9] of link;
function h(key: integer): integer; begin h:=key mod 10; end;
function search(key1: integer; st1: string): link; var i: integer; q, p, s: link; begin i:= h(key1); q:=nil; p:=mas[i]; while p <> nil do begin if p^.key = key1 then begin search:=p; exit; end; q := p; p := p^.link; end; {Если ключ не найден, вставляем новую запись} new(s); s^.key:=key1; s^.st:=st1; s^.next:=nil; if q = nil then mas[i]:=s else q^.next:=s; search:=s; end;
|
Попытался его перевести в C++:
| Код | typedef struct node { int key; string st; // В структуре вообще запутался :( node *link; //node *next; }link;
link mas[9];
int h(int key) { return key % 10; }
link search(int key1, string st1) { int i; link q,p,s;
i = h(key1); q = NULL; // ругается на эту строку p = mas[i]; while (p != NULL) { // тоже ругается if (*p->key = key1) { search = p; exit(); } q = p; p = *p->link; } malloc(s); *s->key = key; *s->st = st1; *s->next = NULL;
if (q == NULL) { mas[i] = s; } else { *q->next = s; } search = s; }
|
Помогите исправить мои ошибки. Спасибо. |