通过控制台在Typescript中创建并测试简单列表

通过控制台在Typescript中创建并测试简单列表,typescript,Typescript,我将创建简单的方法来创建,并从Typescript中的列表中获取一个数字。我不知道该怎么做。 有人能帮我得到第一个方法吗? 下面是我们得到的代码: class ListElement { public next: ListElement; public value: number; } abstract class List { protected first: ListElement; protected current: ListElement;

我将创建简单的方法来创建,并从Typescript中的列表中获取一个数字。我不知道该怎么做。 有人能帮我得到第一个方法吗? 下面是我们得到的代码:

class ListElement {
    public next: ListElement;
    public value: number;
}

abstract class List {
    protected first: ListElement;
    protected current: ListElement;

    public abstract add(value: number): void;

    public abstract remove(index: number): void;

    public abstract get(index: number): number;

    public abstract hasNext(): boolean;

    public abstract next(): number;

    public abstract clear(): void;
}

//here your code:

var array = new Array();

class MyList extends List{

    public add(): void{

    }
    public remove(): void{

    }
    public  get(): any{

    }
    public hasNext(): any{

    }
    public next(): any{

    }
    public clear(): void{


    }
}

//until here

let testListe: List = new MyList();
testListe.add(4);
testListe.add(2);
testListe.add(7);
testListe.add(100);
testListe.add(10);

testListe.remove(3);
testListe.remove(4);

console.log("Should be 10 : " + testListe.get(3));
console.log("Should be 4 : " + testListe.get(0));

console.log("Should be 2, 7, 10");
while(testListe.hasNext()) {
    console.log(testListe.next());
}

console.log("Should be undefined : " + testListe.next());

testListe.clear();
console.log("Should be undefined : " + testListe.get(0));

欢迎来到SO!请花些时间阅读文章,以及元帖子。也就是说,您提供的代码看起来有点太薄了——至少自己尝试实现这些方法。我不确定代码是否应该使用数组。成员
first
current
提示使用链接元素实现列表。这听起来很像是有人必须实现一个链接列表作为学校作业。:)