From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id CAA04496; Wed, 14 Aug 2002 02:56:14 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id CAA04460 for ; Wed, 14 Aug 2002 02:56:13 +0200 (MET DST) Received: from viola.sinor.ru (viola.sinor.ru [217.70.106.9]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id g7E0uBL06602 for ; Wed, 14 Aug 2002 02:56:12 +0200 (MET DST) Received: from sibnet.ru (tlg5-ppp84.sibnet.ru [217.70.116.84]) by viola.sinor.ru (8.12.3/8.12.3) with ESMTP id g7E0u6rY030187 for ; Wed, 14 Aug 2002 07:56:06 +0700 Received: by sibnet.ru id m17emM9-001EocC; Wed, 14 Aug 2002 07:49:49 +0700 (NOVST) Date: Wed, 14 Aug 2002 07:49:48 +0700 From: Max Kirillov To: caml-list@inria.fr Subject: Re: [Caml-list] Doubly-linked list Message-ID: <20020814074948.B4141@max.home> Mail-Followup-To: caml-list@inria.fr References: <200208131430.KAA23206@hickory.cc.columbia.edu> <012001c242db$ba4c9f90$2be213c3@youngkouzdra> <200208131611.MAA00208@dewberry.cc.columbia.edu> <20020814001625.A4141@max.home> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="GRPZ8SYKNexpdSJ7" Content-Disposition: inline User-Agent: Mutt/1.2.5i In-Reply-To: <20020814001625.A4141@max.home>; from max630@mail.ru on Wed, Aug 14, 2002 at 12:16:25AM +0700 X-Sender: Max Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk --GRPZ8SYKNexpdSJ7 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline I should stop sitting after 24. At least don't send anything. It's full of errors. It's not an ocaml at all... Sorry. Max. --GRPZ8SYKNexpdSJ7 Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="dlist.ml" type 'a t = {mutable prev : 'a t option; mutable next : 'a t option; info : 'a} type 'a dlist = {mutable front: 'a t; mutable back: 'a t} exception Bound let next = function {next=Some obj1} -> obj1 | _ -> raise Bound let prev = function {prev=Some obj1} -> obj1 | _ -> raise Bound let takeNext objR = objR:=(next !objR) let takePrev objR = objR:=(prev !objR) let add_before v obj = let newObj = {prev=None;next=Some obj;info=v} in (match obj with {prev=Some obj1} -> (newObj.prev<-Some obj1; obj1.next<-Some newObj) | {prev=None} -> ()); obj.prev<-Some newObj let add_after v obj = let newObj = {next=None;prev=Some obj;info=v} in (match obj with {next=Some obj1} -> (newObj.next<-Some obj1; obj1.prev<-Some newObj) | {next=None} -> ()); obj.next<-Some newObj (* Hmm... I'm not clear whether front is after back or before it. Depends on moving direction:) Let's suppose before *) let push_back v ({back=obj} as data) = add_after v obj; data.back <- next obj let push_front v ({front=obj} as data) = add_before v obj; data.front <- prev obj --GRPZ8SYKNexpdSJ7-- ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners