classOrderedStream:def__init__(self,n:int):self.ptr=1self.data=[None]*(n+1)definsert(self,idKey:int,value:str)->List[str]:self.data[idKey]=valueans=[]whileself.ptr<len(self.data)andself.data[self.ptr]:ans.append(self.data[self.ptr])self.ptr+=1returnans# Your OrderedStream object will be instantiated and called as such:# obj = OrderedStream(n)# param_1 = obj.insert(idKey,value)
1 2 3 4 5 6 7 8 91011121314151617181920212223
classOrderedStream{privateintptr=1;privateString[]data;publicOrderedStream(intn){data=newString[n+1];}publicList<String>insert(intidKey,Stringvalue){data[idKey]=value;List<String>ans=newArrayList<>();while(ptr<data.length&&data[ptr]!=null){ans.add(data[ptr++]);}returnans;}}/** * Your OrderedStream object will be instantiated and called as such: * OrderedStream obj = new OrderedStream(n); * List<String> param_1 = obj.insert(idKey,value); */
classOrderedStream{public:OrderedStream(intn){ptr=1;data=vector<string>(n+1);}vector<string>insert(intidKey,stringvalue){data[idKey]=value;vector<string>ans;while(ptr<data.size()&&!data[ptr].empty()){ans.push_back(data[ptr++]);}returnans;}private:intptr;vector<string>data;};/** * Your OrderedStream object will be instantiated and called as such: * OrderedStream* obj = new OrderedStream(n); * vector<string> param_1 = obj->insert(idKey,value); */
typeOrderedStreamstruct{ptrintdata[]string}funcConstructor(nint)OrderedStream{returnOrderedStream{ptr:1,data:make([]string,n+1),}}func(this*OrderedStream)Insert(idKeyint,valuestring)[]string{this.data[idKey]=valuevarans[]stringforthis.ptr<len(this.data)&&this.data[this.ptr]!=""{ans=append(ans,this.data[this.ptr])this.ptr++}returnans}/** * Your OrderedStream object will be instantiated and called as such: * obj := Constructor(n); * param_1 := obj.Insert(idKey,value); */
1 2 3 4 5 6 7 8 9101112131415161718192021222324
classOrderedStream{privateptr:number;privatedata:string[];constructor(n:number){this.ptr=1;this.data=Array(n+1);}insert(idKey:number,value:string):string[]{this.data[idKey]=value;constans:string[]=[];while(this.data[this.ptr]){ans.push(this.data[this.ptr++]);}returnans;}}/** * Your OrderedStream object will be instantiated and called as such: * var obj = new OrderedStream(n) * var param_1 = obj.insert(idKey,value) */