I need to create a linked list where I can continue to input integers and I'm not sure what I'm doing wrong, but every time I run it I'm allowed to enter two numbers and then I get exit code 216 saying I'm accessing memory I'm not allowed to.

Program List;
uses
        crt;
type
    RecMemLoc= ^Rec;
               Rec=Record
                         Data:integer;
                         Next: RecMemLoc;
                   end;

var
   MemLoc: ^integer;
   Num: RecMemLoc;
   New: RecMemLoc;

Procedure Input(var Num, New: RecMemLoc);

var
   choice:char;

Begin
     New(Num);
     Writeln('Input Num');
     Readln(Num^.Data);
     Repeat
           Begin
                clrscr;
                Writeln('Do you want to enter another number?');
                readln(Choice);
                New(New);
                New:=Num;
                New:=New^.Next;
                Writeln('Input Number');
                Readln(New^.Data);
           End;
     Until(Choice='N');
     New:=New^.Next;
     New:=Nil;
End;

Procedure Output(var Num, New: RecMemLoc);

Begin
     write(Num^.Data);
     Repeat
           Begin
                New:=Num;
                New:=New^.Next;
                write(New^.Data);
           end;
     Until(New=Nil);
End;

Begin
     clrscr;
     input(Num, New);
     output(Num, New);
     readln;
End.

Recommended Answers

All 4 Replies

anyone?? PLEASE!!

I really just need help creating the linked list..

Program LinkedList;

Uses Crt;

TYPE
     DataType = integer;

     NodePtr = ^ NodeType;
     NodeType = RECORD
                  Data : DataType;
                  Next : NodePtr;
                END;

VAR
    Head, Temp : NodePtr;

{ add at end of list }
PROCEDURE AddNode(VAR H : NodePtr; Item : DataType);
VAR
    NewNode, Temp : NodePtr;
BEGIN
     New(NewNode);
     NewNode^.Data := Item;
     NewNode^.Next := NIL;
     If H = NIL THEN H := NewNode
     ELSE
          begin
               Temp := H;
               WHILE (Temp^.Next <> NIL) DO { find last node }
               Temp := Temp^.Next;
               Temp^.Next := NewNode;
          end;
END;

PROCEDURE ShowNode(H : NodePtr);
VAR
    Temp : NodePtr;
BEGIN
     Temp := H;
     While Temp <> NIL DO
     begin
          write(Temp^.Data:4);
          Temp := Temp^.Next;
     end;
END;

PROCEDURE DestroyList(H : NodePtr); (*do not forget it!*)
BEGIN
     IF H^.Next <> NIL THEN
     DestroyList(H^.Next);
     Dispose(H);
END;

BEGIN { main }
      Clrscr;
      Head:=NIL; { list is empty at the beginning }
      AddNode(Head,10);
      AddNode(Head,20);
      AddNode(Head,34);
      AddNode(Head,44);
      AddNode(Head,12);
      AddNode(Head,38);
      ShowNode(Head); { display all nodes }
      DestroyList(Head); { done with list so free up memory }
      ReadKey;
END.

Listen this code,compare with yours.
Next time do not use reserved word as your identifier...

Thank you for the help :D

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.