Algorithms. M. R. C. van Dongen. ucc. LaTEX and Friends Algorithms. Marc van Dongen. Algorithms and Listings

Similar documents
M. R. C. van Dongen. ucc. LaTEX and Friends. Including External Pictures. Marc van Dongen.

Branching. M. R. C. van Dongen. ucc. LaTEX and Friends Branching. Marc van Dongen.

M. R. C. van Dongen. ucc. LaTEX and Friends. Commands and Environments. Marc van Dongen

L A TEX Overview. Jiayi Liu. January 31, Colorado School of Mines

PROGRAMMING FUNDAMENTALS

COMPUTER PROGRAMMING LOOPS

Loops. CSE 114, Computer Science 1 Stony Brook University

Lecture 1: Short summary of LaTeX basics

Relational Operators. > greater than < less than >= greater than or equal to <= less than or equal to <> not equal to = equal to

How to Write a Thesis

LATEX TYPESETTING SYSTEM. CAAM 519, CHAPTER 3

Latex Tutorial. CIS400 Senior Design 9/5/2013

Algorithms. Rogério Brito July 5, 2005

St. Catherine s High School

Lecture 14 CSE11 Fall 2013 For loops, Do While, Break, Continue

Introduction to LATEX

Pace University. Fundamental Concepts of CS121 1

Computer Components. Software{ User Programs. Operating System. Hardware

Excellent support for mathematical formatting. Automatically downloads/installs missing components as needed Updates somewhat frequently

Java Tutorial. Saarland University. Ashkan Taslimi. Tutorial 3 September 6, 2011

Chapter 2: Functions and Control Structures

What is PHP? [1] Figure 1 [1]

Introduction to C++ Introduction. Structure of a C++ Program. Structure of a C++ Program. C++ widely-used general-purpose programming language

Symbolic Computation and Common Lisp

Introduction to C++ with content from

Algorithms. Rogério Brito 16 March 2005

An Introduction to L A T E X

Programming with Java

GE PROBLEM SOVING AND PYTHON PROGRAMMING. Question Bank UNIT 1 - ALGORITHMIC PROBLEM SOLVING

Java is an objet-oriented programming language providing features that support

egrapher Language Reference Manual

My Full-Length Title

Object-oriented programming. and data-structures CS/ENGRD 2110 SUMMER 2018

Lecture 2. COMP1406/1006 (the Java course) Fall M. Jason Hinek Carleton University

Visual Studio.NET.NET Framework. Web Services Web Forms Windows Forms. Data and XML classes. Framework Base Classes. Common Language Runtime

Outline. Parts 1 to 3 introduce and sketch out the ideas of OOP. Part 5 deals with these ideas in closer detail.

( &% class MyClass { }

CPSC 3740 Programming Languages University of Lethbridge. Control Structures

Introduction to LATEX

Computer Components. Software{ User Programs. Operating System. Hardware

BIT Java Programming. Sem 1 Session 2011/12. Chapter 2 JAVA. basic

LATEX, BibTEX, and Friends. Robert Buels. Outline. What is LATEX. Using BibTEX LYX the graphical LATEX Managing your BibTEX references Further reading

Software and Programming 1

Java Control Statements

Latex Manually Set Font Size For Tables

TTh 9.25 AM AM Strain 322

Java Programming. Atul Prakash

Programming for the Web with PHP

Full file at

Alpha College of Engineering and Technology. Question Bank

1007 Imperative Programming Part II

TUTORIAL 5: LIST ENVIRONMENTS. 1. Welcome. (1) Hello. My name is Dr. Christopher Raridan (Dr. R).

Section 2.2 Your First Program in Java: Printing a Line of Text

Exam Duration: 2hrs and 30min Software Design

This is the LYX Beamer Template

ava with Object-Oriented Generic Programming+ Java Java with Object-Oriented + Generic Programming by Paul S. Wang sofpower.com

CS 251 Intermediate Programming Java Basics

Intro History Version 2 Problems Software Future. Dr. StrangeBook. or: How I Learned to Stop Worrying and Love XML. Nigel Stanger

PHP Hypertext Preprocessor

A Brief Introduction to L A T E X

Review. Primitive Data Types & Variables. String Mathematical operators: + - * / % Comparison: < > <= >= == int, long float, double boolean char

CS 251 Intermediate Programming Methods and Classes

CS 251 Intermediate Programming Methods and More

CS 231 Data Structures and Algorithms Fall Event Based Programming Lecture 06 - September 17, Prof. Zadia Codabux

CS 101 Fall 2005 Midterm 2 Name: ID:

WELCOME TO L A TEX 2ɛ!

By Lucas Marshall. All materials Copyright Developer Shed, Inc. except where otherwise noted.

Java Bytecode (binary file)

AP Computer Science Unit 1. Programs

Introduction to Programming (Java) 4/12

HOW TO TYPESET THESES. Using iiscthesis style for LAT E X

Lecture 5. Defining Functions

17 Hello world 18 Type: String: literal 19 Standard API: System: out.println() 20 Hello world 21 Statement 22 Statement: simple statements are ended w

Chapter 5 Control Statements: Part 2 Section 5.2 Essentials of Counter-Controlled Repetition

We have written lots of code so far It has all been inside of the main() method What about a big program? The main() method is going to get really

List of Slides 1 Title 2 Chapter 2: Sequential execution and program errors 3 Chapter aims 4 Section 2: Example:Hello world 5 Aim 6 Class: programs ar

Course Title: Python + Django for Web Application

Java Coding style guide 1. Java. Coding Style Guide. (July 2015)

13 th Windsor Regional Secondary School Computer Programming Competition

CS 211: Methods, Memory, Equality

PHP Personal Home Page PHP: Hypertext Preprocessor (Lecture 35-37)

Programming in Python 3

Goals. Java - An Introduction. Java is Compiled and Interpreted. Architecture Neutral & Portable. Compiled Languages. Introduction to Java

: Primitive data types Variables Operators if, if-else do-while, while, for. // // First Java Program. public class Hello {

CSCI 136 Data Structures & Advanced Programming. Fall 2018 Instructors Bill Lenhart & Bill Jannen

Scala, Your Next Programming Language

Programming for Experimental Research. Flow Control

C212 Early Evaluation Exam Mon Feb Name: Please provide brief (common sense) justifications with your answers below.

Chapter 1 An introduction to relational databases and SQL

Visualize ComplexCities

Programming Language Basics

Introduction Basic elements of Java

A foundation for programming. Classes and objects. Overview. Java primitive types. Primitive types Creating your own data types

An Interactive Introduction to L A TEX. Part 2: Structured Documents & More. Dr John D. Lees-Miller. writel A TEX.

The basics of LaTeX. Cédric Buron. April 25, 2016

INDEX. A SIMPLE JAVA PROGRAM Class Declaration The Main Line. The Line Contains Three Keywords The Output Line

Introduction to Visual Basic and Visual C++ Introduction to Java. JDK Editions. Overview. Lesson 13. Overview

Basic Concepts. Computer Science. Programming history Algorithms Pseudo code. Computer - Science Andrew Case 2

CSCE 110 Programming I Basics of Python: Variables, Expressions, Input/Output

An Introduction to. Rado Ivanov CIS400 Senior Design Tutorial September 18, 2014

Transcription:

and Listings http://csweb.ucc.ie/~dongen/laf/laf.html M. R. C. van Dongen ucc

Loading the Package and Listings Use algorithm2e [Fiorio 2004] for pseudo code algorithms. Choosing right option saves time/space. An important option is algo2e. Renames algorithm to algorithm2e. LaTEX Usage \usepackage[algo2e]{algorithm2e} Several options affect the appearance of the algorithms. noline Omits drawing of vertical lines. lined Vertical line marks the block. Keeps end keywords. vlined Vertical bent line marks the block.

Effect of Using the Different Options if cond then stuff end and Listings if cond then stuff end if cond then stuff

Basic Environments and Listings algorithm Typesets its body as an algorithm. algorithm* Typesets body as algorithm in 2-column document. procedure Typesets its body as a procedure. Caption lists Procedure name. \caption starts with name ( arguments ). procedure* Typesets body as procedure in 2-column document. function Typesets its body as a function. function* Typesets body as function in 2-column document.

LaTEX Usage and Listings \begin{algorithm2e}[h] \KwIn{Integers $a \geq 0$ and $b \geq 0$} \KwOut{\textsc{Gcd} of $a$ and $b$} \While{$b \neq 0$}{ $r \leftarrow a \bmod b$\; $a \leftarrow b$\; $b \leftarrow r$\; } \caption{euclidean Algorithm} \end{algorithm2e} Input: Integers a 0 and b 0 Output: Gcd of a and b while b 0 do r a mod b; a b; b r; Algorithm 1: Euclidean Algorithm

Describing Input and Output and Listings \KwIn{ input } \KwOut{ output } \KwData{ data } \KwResult{ output } In Label : input Out Label : output Data Label : data Result Label : output \KwRet{ return value } Ret Label : return value

Conditional Statements and Listings \If{ condition } { clause } if condition then clause

Conditional Statements and Listings \uif{ condition } { clause } if condition then clause

Conditional Statements and Listings \ElseIf{ condition } { clause } else if condition then clause

Example \begin{algorithm2e}[tbp] \uif{$a < 0$}{ \tcp{$a < 0$} } \uelseif{$a = 0$}{ \tcp{$a = 0$} } \lelse\eif{$a = 1$}{ \tcp{$a = 1$} } { \tcp{$a > 1$} } \end{algorithm2e} if a < 0 then // a < 0 else if a = 0 then // a = 0 else if a = 1 then // a = 1 else // a > 1 and Listings

The Switch Statement and Listings \Switch{ value } { cases } switch value do cases

The Switch Statement (Continued) and Listings \ucase{ condition } { statements } case condition statements

The Switch Statement (Continued) and Listings \Other{ statements } otherwise statements

Example \begin{algorithm2e}[tbp] \Switch{order}{ \ucase{bloody mary}{ Add tomato juice\; Add vodka\; break\; } \ucase{hot whiskey}{ Add whiskey\; Add hot water\; Add lemon and cloves\; Add sugar or honey to taste\; break\; } \Other{Serve water\;} } \end{algorithm2e} switch order do case bloody mary Add tomato juice; Add vodka; break; case hot whiskey Add whiskey; Add hot water; Add lemon and cloves; Add sugar or honey to taste; break; otherwise Serve water; and Listings

Iterative Statements and Listings \For{ condition } { body } for condition do body

Iterative Statements (Continued) and Listings \ForEach{ condition } { body } foreach condition do body

Iterative Statements (Continued) and Listings \While{ condition } { body } while condition do body

Comments and Listings \tcp{ line one }\\ { line two } // line one // line two

Comments (Continued) and Listings statement \tcp*{ comment } statement ; // comment

Comments (Continued) and Listings \If(\tcp*[h]{ comment }) { condition } { statement } if condition then // comment statement

Typeset listings with listings [Heinz, and Moses 2007]. Support for several languages: ANSI C, and ANSI C++, Eiffel, HTML, Java, PHP, Python, LaTEX, and XML. Supports different styles for keywords and identifiers. Two methods for specifying a listing: environment For specifying a listing. command For creating a listing from a file. Provides command to specify new defaults. Result is typeset in place or as a float. Provides command for typesetting list of listings. and Listings

First Example and Listings \begin{lstlisting}[language=java,gobble=3,numbers=left,firstline=2,lastline=4,firstnumber=2,caption=hello World.,label=example] public class Greetings { public static void main( String[] args ) { System.out.println( "Hello world!" ); } } \end{lstlisting}

First Example (Continued) and Listings 2 public static void main( String[] args ) { 3 System.out.println( "Hello world!" ); 4 } Listing 1. Hello world.

Specifying Defaults and Listings LaTEX Usage \lstset{language=java%,keywordstyle=\bfseries\ttfamily%,stringstyle=\ttfamily%,identifierstyle=\ttfamily\itshape%,showspaces=false%,showstringspaces=true%,numbers=left%,float%,floatplacement=tbp%,captionpos=b}

Bibliography and Listings Fiorio, Christophe [14th Dec. 2004]. algorithm2e.sty package for algorithms. Version 3.3. Heinz, Carsten, and Brooks Moses [22nd Feb. 2007]. The Listings Package. Version 1.4.

Acronyms and ams American Mathematical Society api Application Programming Interface apl A Programming Language ctan Comprehensive TEX Archive Network cd Compact Disk faq Frequently Asked Question gui Graphical User Interface ide Integrated Development Environment isbn International Standard Book Number os Operating System si Système International d Unités/International System of Units tug TEX Users Group url Uniform Resource Locator wysiwyg What You See Is What You Get and Listings

and Listings This document was created with pdflatex. The LaTEX document class is beamer.