Discussion:
ADT:LinkedList
(too old to reply)
fitzer8
2009-08-24 23:51:47 UTC
Permalink
Hey gang,

I'm using oo2c 32-2.1.11, and I'm trying to figure out how to use
ADT:LinkedList.

Does anybody have a simple program that uses this? I would like to use
it as a reference.

TIA,
Fitz
August Karlstrom
2009-08-25 19:25:38 UTC
Permalink
Post by fitzer8
Hey gang,
I'm using oo2c 32-2.1.11, and I'm trying to figure out how to use
ADT:LinkedList.
Does anybody have a simple program that uses this? I would like to use
it as a reference.
I have never used it but after browsing through the documentation I
wrote the following example:

MODULE Example;

IMPORT Out, ADT:LinkedList, Object;

TYPE
Entry = POINTER TO EntryDesc;
EntryDesc = RECORD (Object.ObjectDesc)
value: INTEGER
END;

VAR
ls: LinkedList.LinkedList;
e: Entry;
x: Object.Object;

BEGIN
ls := LinkedList.New();
NEW(e);
e.value := 37;
ls.Insert(0, e);
x := ls.Get(0);
Out.Int(x(Entry).value, 0);
Out.Ln
END Example.


/August
Sambo
2009-08-25 20:16:18 UTC
Permalink
Post by August Karlstrom
Post by fitzer8
Hey gang,
I'm using oo2c 32-2.1.11, and I'm trying to figure out how to use
ADT:LinkedList.
Does anybody have a simple program that uses this? I would like to use
it as a reference.
I have never used it but after browsing through the documentation I
MODULE Example;
        IMPORT Out, ADT:LinkedList, Object;
        TYPE
                Entry = POINTER TO EntryDesc;
                EntryDesc = RECORD (Object.ObjectDesc)
                        value: INTEGER
                END;
        VAR
                ls: LinkedList.LinkedList;
                e: Entry;
                x: Object.Object;
BEGIN
        ls := LinkedList.New();
        NEW(e);
        e.value := 37;
        ls.Insert(0, e);
        x := ls.Get(0);
        Out.Int(x(Entry).value, 0);
        Out.Ln
END Example.
/August
August,

That's perfect. Thank you so much for your assistance.

Now that I've seen what I was missing, it was relatively simple.
I'll just claim it was a senior moment. ;^)

Thank you again,
Fitz
Stewart Greenhill
2009-08-28 13:02:51 UTC
Permalink
Post by August Karlstrom
Post by fitzer8
Hey gang,
I'm using oo2c 32-2.1.11, and I'm trying to figure out how to use
ADT:LinkedList.
Does anybody have a simple program that uses this? I would like to use
it as a reference.
I have never used it but after browsing through the documentation I
MODULE Example;
IMPORT Out, ADT:LinkedList, Object;
TYPE
Entry = POINTER TO EntryDesc;
EntryDesc = RECORD (Object.ObjectDesc)
value: INTEGER
END;
VAR
ls: LinkedList.LinkedList;
e: Entry;
x: Object.Object;
BEGIN
ls := LinkedList.New();
NEW(e);
e.value := 37;
ls.Insert(0, e);
x := ls.Get(0);
Out.Int(x(Entry).value, 0);
Out.Ln
END Example.
This is exactly how the original ADT:LinkedList worked.

In Version 2 of the compiler, all collection types in ADT (eg.
LinkedList, ArrayList, Dictionary) became parametric (ie. generic). If
you don't specify a type parameter it assumes the bound type which
generally is Object.ObjectDesc. It is still completely compatible with
the old style usage, but you can now do this sort of thing too:

MODULE TestLinkedList;

IMPORT Out, ADT:LinkedList, Object;

TYPE
Entry = POINTER TO EntryDesc;
EntryDesc = RECORD (Object.ObjectDesc)
value: INTEGER
END;

VAR
ls: LinkedList.LinkedList(Entry);
e: Entry;

BEGIN
ls := NEW(LinkedList.LinkedList(Entry));

NEW(e);
e.value := 37;

ls.Insert(0, e);
e := ls.Get(0);

Out.Int(e.value, 0);
Out.Ln
END TestLinkedList.


MODULE Object:Boxed gives you object wrappers for all of the basic
Oberon types. So the following is equivalent to the previous example:

MODULE TestLinkedList2;

IMPORT Out, ADT:LinkedList, Object:Boxed;

TYPE
IntList = LinkedList.LinkedList(Boxed.LongInt);

VAR
ls: IntList;
e : Boxed.LongInt;

BEGIN
ls := NEW(IntList);

e := NEW(Boxed.LongInt, 37);

ls.Insert(0, e);

e := ls.Get(0);

Out.Int(e.value, 0);
Out.Ln
END TestLinkedList2.


If you're just dealing with text, remember that the built-in STRING type
is an Object, so you can use it directly as a type parameter. Also, ADT
collections have their own iterators which you can use to enumerate the
elements, allowing insertions and deletions as you go. Example:

MODULE TestLinkedList3;

IMPORT Out, ADT:LinkedList;

TYPE
StringList = LinkedList.LinkedList(STRING);

VAR
ls: StringList;
iter : LinkedList.Iterator(STRING);

BEGIN
ls := NEW(StringList);

ls.Append("one");
ls.Prepend("two");
ls.Insert(0, "three");

iter := ls.GetIterator(NIL);

WHILE iter.HasNext() DO
Out.Object(iter.Next());
Out.Ln
END;
END TestLinkedList3.

Hope this helps.

Cheers,
Stewart
Sambo
2009-09-01 01:15:00 UTC
Permalink
Post by Stewart Greenhill
Post by August Karlstrom
Post by fitzer8
Hey gang,
I'm using oo2c 32-2.1.11, and I'm trying to figure out how to use
ADT:LinkedList.
Does anybody have a simple program that uses this? I would like to use
it as a reference.
I have never used it but after browsing through the documentation I
MODULE Example;
    IMPORT Out, ADT:LinkedList, Object;
    TYPE
        Entry = POINTER TO EntryDesc;
        EntryDesc = RECORD (Object.ObjectDesc)
            value: INTEGER
        END;
    VAR
        ls: LinkedList.LinkedList;
        e: Entry;
        x: Object.Object;
BEGIN
    ls := LinkedList.New();
    NEW(e);
    e.value := 37;
    ls.Insert(0, e);
    x := ls.Get(0);
    Out.Int(x(Entry).value, 0);
    Out.Ln
END Example.
This is exactly how the original ADT:LinkedList worked.
In Version 2 of the compiler, all collection types in ADT (eg.
LinkedList, ArrayList, Dictionary) became parametric (ie. generic). If
you don't specify a type parameter it assumes the bound type which
generally is Object.ObjectDesc. It is still completely compatible with
MODULE TestLinkedList;
     IMPORT Out, ADT:LinkedList, Object;
     TYPE
         Entry = POINTER TO EntryDesc;
         EntryDesc = RECORD (Object.ObjectDesc)
             value: INTEGER
         END;
     VAR
         ls: LinkedList.LinkedList(Entry);
         e: Entry;
BEGIN
     ls := NEW(LinkedList.LinkedList(Entry));
     NEW(e);
     e.value := 37;
     ls.Insert(0, e);
     e := ls.Get(0);
     Out.Int(e.value, 0);
     Out.Ln
END TestLinkedList.
MODULE Object:Boxed gives you object wrappers for all of the basic
MODULE TestLinkedList2;
IMPORT Out, ADT:LinkedList, Object:Boxed;
TYPE
   IntList = LinkedList.LinkedList(Boxed.LongInt);
VAR
   ls: IntList;
   e : Boxed.LongInt;
BEGIN
   ls := NEW(IntList);
   e := NEW(Boxed.LongInt, 37);
   ls.Insert(0, e);
   e := ls.Get(0);
   Out.Int(e.value, 0);
   Out.Ln
END TestLinkedList2.
If you're just dealing with text, remember that the built-in STRING type
is an Object, so you can use it directly as a type parameter. Also, ADT
collections have their own iterators which you can use to enumerate the
MODULE TestLinkedList3;
IMPORT Out, ADT:LinkedList;
TYPE
   StringList = LinkedList.LinkedList(STRING);
VAR
   ls: StringList;
   iter : LinkedList.Iterator(STRING);
BEGIN
   ls := NEW(StringList);
   ls.Append("one");
   ls.Prepend("two");
   ls.Insert(0, "three");
   iter := ls.GetIterator(NIL);
   WHILE iter.HasNext() DO
     Out.Object(iter.Next());
     Out.Ln
   END;
END TestLinkedList3.
Hope this helps.
Cheers,
   Stewart
Stewart,

Thank you for your help again.

This did the trick.

Best wishes,
Fitz

Loading...