Karthik Selvakumar Bhuvaneswaran is a Software Engineer working on Saas(RoR) and PaaS(Salesforce.com) applications. He beleives on day starts at night and requires nothing more than Music, a cup of cofee and a fully charged laptop.
classListattr_accessor:data,:nextdefinitialize(d,n)@data=d@next=nenddefdisplaytmp=selfwhile!tmp.nil?print" #{tmp.data} -> "tmp=tmp.nextendprint" END \n"enddefdeleteifself.nextself.data=self.next.dataself.next=self.next.nextendend# Uses stackdefaltrevh=selfst=[]c=0while!h.next.nil?ifc%2==1st.push(h.data)h.deleteelseh=h.nextendc+=1endd=nilwhile(d=st.pop)h.next=List.new(d,nil)h=h.nextendend# Stimulates a stack with 'even' pointerdefaltrev_ph=selfeven=nilc=0while!h.next.nil?ifc%2==0tmp=h.nexth.next=h.next.nextifeven.nil?even=tmpeven.next=nilelsetmp.next=eveneven=tmpendelseh=h.nextendc+=1endh.next=evenendendl=List.new(1,List.new(2,List.new(3,List.new(4,List.new(5,List.new(6,nil))))))l.displayl.altrev_pl.displayl=List.new(12,List.new(14,List.new(16,List.new(18,List.new(20,nil)))))l.displayl.altrev_pl.display