classOrderedStream:def__init__(self,n:int):self.data=[None]*nself.ptr=0definsert(self,idKey:int,value:str)->List[str]:self.data[idKey-1]=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 9101112131415161718192021222324
classOrderedStream{privateString[]data;privateintptr;publicOrderedStream(intn){data=newString[n];ptr=0;}publicList<String>insert(intidKey,Stringvalue){data[idKey-1]=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); */
1 2 3 4 5 6 7 8 910111213141516171819202122
classOrderedStream{public:vector<string>data;intptr=0;OrderedStream(intn){data.resize(n,"");}vector<string>insert(intidKey,stringvalue){data[idKey-1]=value;vector<string>ans;while(ptr<data.size()&&data[ptr]!="")ans.push_back(data[ptr++]);returnans;}};/** * Your OrderedStream object will be instantiated and called as such: * OrderedStream* obj = new OrderedStream(n); * vector<string> param_1 = obj->insert(idKey,value); */
1 2 3 4 5 6 7 8 910111213141516171819202122232425
typeOrderedStreamstruct{data[]stringptrint}funcConstructor(nint)OrderedStream{data:=make([]string,n)returnOrderedStream{data,0}}func(this*OrderedStream)Insert(idKeyint,valuestring)[]string{this.data[idKey-1]=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 910111213141516171819202122232425
classOrderedStream{privateptr:number;privatevals:string[];constructor(n:number){this.ptr=0;this.vals=newArray(n);}insert(idKey:number,value:string):string[]{this.vals[idKey-1]=value;constres=[];while(this.vals[this.ptr]!=null){res.push(this.vals[this.ptr]);this.ptr++;}returnres;}}/** * Your OrderedStream object will be instantiated and called as such: * var obj = new OrderedStream(n) * var param_1 = obj.insert(idKey,value) */
structOrderedStream{ptr:usize,vals:Vec<Option<String>>,}/** * `&self` means the method takes an immutable reference. * If you need a mutable reference, change it to `&mut self` instead. */implOrderedStream{fnnew(n:i32)->Self{Self{ptr:0,vals:vec![None;nasusize],}}fninsert(&mutself,id_key:i32,value:String)->Vec<String>{self.vals[(id_key-1)asusize]=Some(value);letmutres=Vec::new();whileself.ptr<self.vals.len(){ifletSome(s)=&self.vals[self.ptr]{res.push(s.clone());self.ptr+=1;}else{break;}}res}}