Pro3 1 : listes chaînées



Similar documents

Corrigés des exercices SQL pour MySQL

Licence Informatique Année Exceptions

Modifier le texte d'un élément d'un feuillet, en le spécifiant par son numéro d'index:

Liste d'adresses URL

niveau : 1 ere année spécialité : mécatronique & froid et climatisation AU : Programmation C Travaux pratiques

Langages Orientés Objet Java

TP N 10 : Gestion des fichiers Langage JAVA

HEALTH CARE DIRECTIVES ACT

12. A B C A B C A B C 1 A B C A B C A B C JK-FF NETr

1 Dispense scritte da M. Ancona CAPITOLO 2 - HEAP (v 1.0) Dispense di proprietà del DISI

Implementation of SAP-GRC with the Pictet Group

Financial Literacy Resource French As a Second Language: Core French Grade 9 Academic FSF 1D ARGENT EN ACTION! Connections to Financial Literacy

AdaDoc. How to write a module for AdaDoc. August 28, 2002

Annexe - OAuth Introduction. Xavier de Rochefort xderoche@labri.fr - labri.fr/~xderoche 15 mai 2014

Using Safari to Deliver and Debug a Responsive Web Design

Introduction. GEAL Bibliothèque Java pour écrire des algorithmes évolutionnaires. Objectifs. Simplicité Evolution et coévolution Parallélisme

Saruman Documentation

High-Level Programming Languages. Nell Dale & John Lewis (adaptation by Michael Goldwasser)

--- Vincent Hamel, hamv

'NSIA Senegal ' bibliotheque de calcul des fonctions actuarielle. 'stocker les tables sur une feuille avec les noms 'EnsTable 'masquer la feuille

RELEASE NOTES. Trimble TerraSync Software. Introduction 简 介

RAPPORT FINANCIER ANNUEL PORTANT SUR LES COMPTES 2014

Basics of I/O Streams and File I/O

Magento Extension Point of Sales User Manual Version 1.0

SCATS. EDI File Verification. User Manual

Group Projects M1 - Cubbyhole

Service Integration BUS

Office of the Auditor General / Bureau du vérificateur général FOLLOW-UP TO THE 2010 AUDIT OF COMPRESSED WORK WEEK AGREEMENTS 2012 SUIVI DE LA

muriel leray 02/

Tuition Reimbursement Program. Handbook

Precisely Target the Right Audience

Memo bconsole. Memo bconsole

ECE 3401 Lecture 7. Concurrent Statements & Sequential Statements (Process)

PL / SQL Basics. Chapter 3

ESCI 386 IDL Programming for Advanced Earth Science Applications Lesson 6 Program Control

Statistical Pattern-Based Machine Translation with Statistical French-English Machine Translation

Advanced Software Engineering Agile Software Engineering. Version 1.0

Bibliothèque numérique de l enssib

FOR TEACHERS ONLY The University of the State of New York

STAGE YOGA & RANDONNEES à MADERE

ODBC Driver Version 4 Manual

F-Gaz regulation Implementation in France

MIB Application Guide

RcWare SoftPLC Modbus server mapping editor User manual

Computational Mathematics with Python

The Designer's Guide to VHDL

General Certificate of Education Advanced Level Examination June 2012

User Manual FOR KYC Registration Agency

Power Distribution System. Additional Information on page 2 See Page 2 Page 6. Eaton. See Page 2. Additional Information on page 2

HOW TO REGISTER TO HEC EN LIGNE

Tool & Asset Manager 2.0. User's guide 2015

Computational Mathematics with Python

Problem 1 (1.5 points)

II. PREVIOUS RELATED WORK

Archived Content. Contenu archivé

Formulaire de Modification de Données de l Emploi/Job Data Change Form France

«Object-Oriented Multi-Methods in Cecil» Craig Chambers (Cours IFT6310, H08)

AUDITVIEW USER INSTRUCTIONS

DATA_TYPE Values and Data File Storage Formats

The C Programming Language course syllabus associate level

Annual Event 2016 Workshop New to Interreg, where to begin? Évènement annuel 2016 Atelier «Interreg pour les débutants, par où commencer?

Business Software Solutions. Business Plus Accounting Touch POS Quick Start Guide

Calcul parallèle avec R

Using NetBeans IDE to Build Quick UI s Ray Hylock, GISo Tutorial 3/8/2011

Computer Programming I

Form Validation. Server-side Web Development and Programming. What to Validate. Error Prevention. Lecture 7: Input Validation and Error Handling

Upload Center Forms. Contents. Defining Forms 2. Form Options 5. Applying Forms 6. Processing The Data 6. Maxum Development Corp.

Oracle PL/SQL Language. CIS 331: Introduction to Database Systems

Générer des graphiques 3D - Cours Université de Sfax

TIMISKAMING FIRST NATION

El Dorado Union High School District Educational Services

Bash shell programming Part II Control statements

Meilleurs sites / ReferenceMe.com Projet: ReferenceMe.com 20 oct (comparé à 19 oct. 2010)

Immobiline DryStrip Reswelling Tray

Boolean Expressions, Conditions, Loops, and Enumerations. Precedence Rules (from highest to lowest priority)

Technology Business Solutions. Online Backup Manager INSTALLATION

The Tower of Hanoi. Recursion Solution. Recursive Function. Time Complexity. Recursive Thinking. Why Recursion? n! = n* (n-1)!

An Introduction to PL/SQL. Mehdi Azarmi

The Need For Speed. leads to PostgreSQL. Dimitri Fontaine 28 Mars 2013

Cours de Java. Sciences-U Lyon. Java - Introduction Java - Fondamentaux Java Avancé.

Titanium Schedule Client Import Guide

1 ST CONNECTION: HOW TO CREATE YOUR WEB ACCOUNT?

Transcription:

Initiation à l algorithmique, L2 2005-2006, JC Fournier 3.1 Pro3 1 : listes chaînées Spécification : 1 generic 2 type element i s private ; 3 package l i s t e s c h a i n is 4 5 type position is private ; 6 type l i s t e is limited private ; 7 8 function est vide (L : l i s t e ) return boolean ; 9 function trouver (x : element ; L : l i s t e ) return position ; 10 function trouver prec (x : element ; L : l i s t e ) return position ; 11 function prem pos (L : l i s t e ) return position ; 12 function est der pos (p : position ; L : l i s t e ) return boolean ; 13 procedure avance pos (p : in out position ; L : l i s t e ) ; 14 function recup elt (p : position ; L : l i s t e ) return element ; 15 procedure inserer (x : element ; L : l i s t e ; p : position ) ; 16 procedure inserer debut (x : element ; L : l i s t e ) ; 17 procedure supprimer (x : element ; L : l i s t e ) ; 18 procedure c r e e r l i s t e (L : in out l i s t e ) ; 19 procedure v i d e r l i s t e (L : in out l i s t e ) ; 20 21 non trouve, f i n l i s t e : exception ; 22 23 private 24 type noeud ; 25 type position is access noeud ; 26 type noeud i s record 27 e l t : element ; 28 suiv : position ; 29 end record ; 30 type l i s t e is new position ; 31 32 end l i s t e s c h a i n ;

Initiation à l algorithmique, L2 2005-2006, JC Fournier 3.2 Corps : 1 with Ada. unchecked deallocation ; 2 package body l i s t e s c h a i n is 3 4 procedure l i b e r e r is 5 new Ada. unchecked deallocation (noeud, position ) ; 6 7 function est vide (L : l i s t e ) return boolean is 8 begin 9 return L. suiv = null ; 10 end est vide ; 11 12 function trouver (x : element ; L : l i s t e ) return position is 13 p : position := L. suiv ; 14 begin 15 while p /= null and then p. e l t /= x loop 16 p := p. suiv ; 17 end loop ; 18 if p = null then 19 raise non trouve ; 20 end if ; 21 return p ; 22 end trouver ; 23 24 function trouver prec (x : element ; L : l i s t e ) 25 return position is 26 p : position := position (L); 27 q : position ; 28 begin 29 while p /= null and then p. e l t /= x loop 30 q := p ; 31 p := p. suiv ; 32 end loop ; 33 if p = null then 34 raise non trouve ; 35 end if ; 36 return q ; 37 end trouver prec ;

Initiation à l algorithmique, L2 2005-2006, JC Fournier 3.3 38 39 function prem pos (L : l i s t e ) return position is 40 retourne null si la l i s t e est vide 41 begin 42 return L. suiv ; 43 end prem pos ; 44 45 function est der pos (p : position ; L : l i s t e ) 46 return boolean is 47 begin 48 return p. suiv = null ; 49 end est der pos ; 50 51 procedure avance pos (p : in out position ; L : l i s t e ) is 52 begin 53 if est der pos (p, L) then 54 raise f i n l i s t e ; 55 end if ; 56 p := p. suiv ; 57 end avance pos ; 58 59 function recup elt (p : position ; L : l i s t e ) return element is 60 begin 61 if p = null then 62 raise non trouve ; 63 else 64 return p. e l t ; 65 end if ; 66 end recup elt ; 67 68 procedure inserer (x : element ; L : l i s t e ; p : position ) is 69 begin 70 if p = null then 71 raise non trouve ; 72 else 73 p. suiv := new noeud ( x, p. suiv ) ; 74 end if ; 75 end inserer ; 76

Initiation à l algorithmique, L2 2005-2006, JC Fournier 3.4 77 procedure inserer debut (x : element ; L : l i s t e ) is 78 p : position ; 79 begin 80 p := new noeud ( x, L. suiv ) ; 81 L. suiv := p ; 82 end inserer debut ; 83 84 procedure supprimer (x : element ; L : l i s t e ) is 85 pos prec : position := trouver prec (x, L); 86 pos suppr : position := pos prec. suiv ; 87 begin 88 pos prec. suiv := pos suppr. suiv ; 89 l i b e r e r ( pos suppr ) ; libere l espace 90 end supprimer ; 91 92 procedure c r e e r l i s t e (L : in out l i s t e ) is 93 p : position ; 94 begin 95 p := new noeud ; 96 L := l i s t e (p ) ; 97 end c r e e r l i s t e ; 98 99 procedure v i d e r l i s t e (L : in out l i s t e ) is 100 p : position := L. suiv ; 101 temp : position ; 102 begin 103 L. suiv := null ; 104 while p /= null loop 105 temp := p. suiv ; 106 l i b e r e r (p ) ; 107 p := temp ; 108 end loop ; 109 end v i d e r l i s t e ; 110 111 end l i s t e s c h a i n ;

Initiation à l algorithmique, L2 2005-2006, JC Fournier 3.5 Essai : 1 with l i s t e s c h a i n ; 2 with Ada. text io, Ada. i n t e ger t e x t i o ; 3 use Ada. text io, Ada. i n teger text i o ; 4 5 procedure e s s a i l i s t e s c h a i n is 6 7 package l i s t e s c h a i n e n t is new l i s t e s c h a i n ( integer ) ; 8 use l i s t e s c h a i n e n t ; 9 10 L : l i s t e ; 11 p : position ; 12 x : integer ; 13 r : character ; 14 15 procedure aff menu is 16 begin 17 put ( MENU ) ; new line ; 18 put ( a : ajouter dans la l i s t e ) ; new line ; 19 put ( s : supprimer un element ) ; new line ; 20 put ( f : a f fi c h e r la l i s t e ) ; new line ; 21 put ( q : quitter ) ; new line ; 22 end aff menu ; 23 24 procedure ajout dans liste (L : l i s t e ) is 25 x : integer ; 26 begin 27 put ( Donner l entier a ajouter dans la l i s t e : ) ; 28 get (x ) ; 29 inserer debut (x, L); 30 end ajout dans liste ; 31 32 procedure suppr dans liste (L : l i s t e ) is 33 begin 34 put ( Donner l entier a supprimer de la l i s t e : ) ; 35 get (x ) ; 36 supprimer (x, L); 37 exception

Initiation à l algorithmique, L2 2005-2006, JC Fournier 3.6 38 when non trouve => 39 put ( impossible supprimer, element non dans la l i s t e ) ; 40 new line ; 41 end suppr dans liste ; 42 43 procedure a f f i c h l i s t e (L : l i s t e ) is 44 p : position ; 45 begin 46 if est vide (L) then 47 put ( l i s t e vide ) ; 48 else 49 p := prem pos (L); 50 loop 51 put ( recup elt (p, L ) ) ; 52 exit when est der pos (p, L); 53 avance pos (p, L) ; 54 end loop ; 55 put ( fin l i s t e ) ; 56 end if ; 57 new line ; 58 end a f f i c h l i s t e ; 59 60 begin 61 c r e e r l i s t e (L); 62 aff menu ; 63 loop 64 put ( choix : ) ; get ( r ) ; 65 case r is 66 when a => ajout dans liste (L); 67 when s => suppr dans liste (L); 68 when f => a f f i c h l i s t e (L); 69 when v => v i d e r l i s t e (L); 70 when q => put ( Au revoir ) ; new line ; exit ; 71 when others => put ( erreur de choix ) ; new line ; 72 end case ; 73 end loop ; 74 end e s s a i l i s t e s c h a i n ;