Advanced Use of Pointers. CS2023 Winter 2004

Similar documents
An Example file... log.txt


LA PRISE DE CALAIS. çoys, çoys, har - dis. çoys, dis. tons, mantz, tons, Gas. c est. à ce. C est à ce. coup, c est à ce

" #$ P UTS W U X [ZY \ Z _ `a \ dfe ih j mlk n p q sr t u s q e ps s t x q s y i_z { U U z W } y ~ y x t i e l US T { d ƒ ƒ ƒ j s q e uˆ ps i ˆ p q y

Optimal Control of PDEs

Framework for functional tree simulation applied to 'golden delicious' apple trees

General Neoclassical Closure Theory: Diagonalizing the Drift Kinetic Operator

Vectors. Teaching Learning Point. Ç, where OP. l m n

$%! & (, -3 / 0 4, 5 6/ 6 +7, 6 8 9/ 5 :/ 5 A BDC EF G H I EJ KL N G H I. ] ^ _ ` _ ^ a b=c o e f p a q i h f i a j k e i l _ ^ m=c n ^

An Introduction to Optimal Control Applied to Disease Models

Queues, Stack Modules, and Abstract Data Types. CS2023 Winter 2004

ALTER TABLE Employee ADD ( Mname VARCHAR2(20), Birthday DATE );

The University of Bath School of Management is one of the oldest established management schools in Britain. It enjoys an international reputation for

QUESTIONS ON QUARKONIUM PRODUCTION IN NUCLEAR COLLISIONS

Matrices and Determinants

Front-end. Organization of a Modern Compiler. Middle1. Middle2. Back-end. converted to control flow) Representation

Max. Input Power (W) Input Current (Arms) Dimming. Enclosure

Obtain from theory/experiment a value for the absorbtion cross-section. Calculate the number of atoms/ions/molecules giving rise to the line.

A Functional Quantum Programming Language

Homework #3. 1 x. dx. It therefore follows that a sum of the

Loop parallelization using compiler analysis

Another Explanation of the Cosmological Redshift. April 6, 2010.

Planning for Reactive Behaviors in Hide and Seek

Surfaces of Section I

OC330C. Wiring Diagram. Recommended PKH- P35 / P50 GALH PKA- RP35 / RP50. Remarks (Drawing No.) No. Parts No. Parts Name Specifications

Examination paper for TFY4240 Electromagnetic theory

A s device signals an interrupt. time-> time T. A s device. starts device. starts device. A s ISR. WAIT/block. Process A. interrupt.

Redoing the Foundations of Decision Theory

A Study on Dental Health Awareness of High School Students

Principal Secretary to Government Haryana, Town & Country Planning Department, Haryana, Chandigarh.

Plasma diagnostics and abundance determinations for planetary nebulae current status. Xiaowei Liu Department of Astronomy, Peking University

F O R SOCI AL WORK RESE ARCH

Towards a High Level Quantum Programming Language

This document has been prepared by Sunder Kidambi with the blessings of

Pharmacological and genomic profiling identifies NF-κB targeted treatment strategies for mantle cell lymphoma

Symbols and dingbats. A 41 Α a 61 α À K cb ➋ à esc. Á g e7 á esc. Â e e5 â. Ã L cc ➌ ã esc ~ Ä esc : ä esc : Å esc * å esc *

TELEMATICS LINK LEADS

Books. Book Collection Editor. Editor. Name Name Company. Title "SA" A tree pattern. A database instance

New method for solving nonlinear sum of ratios problem based on simplicial bisection

1. Installing ActiveSync Downloading Files 36

Some emission processes are intrinsically polarised e.g. synchrotron radiation.

New BaBar Results on Rare Leptonic B Decays

Rarefied Gas FlowThroughan Orifice at Finite Pressure Ratio

ETIKA V PROFESII PSYCHOLÓGA

A Study on the Analysis of Measurement Errors of Specific Gravity Meter

1. Allstate Group Critical Illness Claim Form: When filing Critical Illness claim, please be sure to include the following:

Relation Between the Growth Twin and the Morphology of a Czochralski Silicon Single Crystal

Constructive Decision Theory

Modern Physics. Unit 5: Schrödinger s Equation and the Hydrogen Atom Lecture 5.6: Energy Eigenvalues of Schrödinger s Equation for the Hydrogen Atom

UNIQUE FJORDS AND THE ROYAL CAPITALS UNIQUE FJORDS & THE NORTH CAPE & UNIQUE NORTHERN CAPITALS

Damping Ring Requirements for 3 TeV CLIC

SOLAR MORTEC INDUSTRIES.

Complex Analysis. PH 503 Course TM. Charudatt Kadolkar Indian Institute of Technology, Guwahati

Search sequence databases 3 10/25/2016

Vector analysis. 1 Scalars and vectors. Fields. Coordinate systems 1. 2 The operator The gradient, divergence, curl, and Laplacian...

PART IV LIVESTOCK, POULTRY AND FISH PRODUCTION

AN IDENTIFICATION ALGORITHM FOR ARMAX SYSTEMS

Research of Application the Virtual Reality Technology in Chemistry Education


Towards a numerical solution of the "1/2 vs. 3/2" puzzle

Sample Exam 1: Chapters 1, 2, and 3

A Theory of Universal AI

T T V e g em D e j ) a S D } a o "m ek j g ed b m "d mq m [ d, )

A Beamforming Method for Blind Calibration of Time-Interleaved A/D Converters

Synchronizing Automata Preserving a Chain of Partial Orders

Lecture 26: Quadrature (90º) Hybrid.

Search for MSSM Higgs at LEP. Haijun Yang. University of Michigan, Ann Arbor

February 17, 2015 REQUEST FOR PROPOSALS. For Columbus Metropolitan Library. Issued by: Purchasing Division 96 S. Grant Ave. Columbus, OH 43215

Permutation distance measures for memetic algorithms with population management

Testing SUSY Dark Matter

SCOTT PLUMMER ASHTON ANTONETTI

31 1 Vol.31, Sup Systems Engineering Theory & Practice Oct., Research on omni directional control of Mecanum wheel mobile robot

Connection equations with stream variables are generated in a model when using the # $ % () operator or the & ' %

DISSIPATIVE SYSTEMS. Lectures by. Jan C. Willems. K.U. Leuven

That is, we start with a general matrix: And end with a simpler matrix:

UNIT TEST - I Name :...

Klour Q» m i o r L l V I* , tr a d itim i rvpf tr.j UiC lin» tv'ilit* m in 's *** O.hi nf Iiir i * ii, B.lly Q t " '

Higher order derivatives

Answer Homework 5 PHA5127 Fall 1999 Jeff Stark

4.3 Laplace Transform in Linear System Analysis

( ) Chapter 6 ( ) ( ) ( ) ( ) Exercise Set The greatest common factor is x + 3.

Winstar Display Co., LTD

Least Favorable Distributions to Facilitate the Design of Detection Systems with Sensors at Deterministic Locations

Building Products Ltd. G Jf. CIN No. L26922KA199SPLC018990

Lecture 27: The 180º Hybrid.

Aim To manage files and directories using Linux commands. 1. file Examines the type of the given file or directory

Unit 3. Digital encoding

5. B To determine all the holes and asymptotes of the equation: y = bdc dced f gbd

I118 Graphs and Automata

236 Chapter 4 Applications of Derivatives

The Language of SOCIAL MEDIA. Christine Dugan

Optimizing Stresses for Testing DRAM Cell Defects Using Electrical Simulation

Ed S MArket. NarROW } ] T O P [ { U S E R S G U I D E. urrrrrrrrrrrv

Application of ICA and PCA to extracting structure from stock return

Dimethyl Ether Production using a Reactive Distillation Process

The incident energy per unit area on the electron is given by the Poynting vector, '

CSC Metric Embeddings Lecture 8: Sparsest Cut and Embedding to

Executive Committee and Officers ( )

A Brief and Elementary Note on Redshift. May 26, 2010.

h : sh +i F J a n W i m +i F D eh, 1 ; 5 i A cl m i n i sh» si N «q a : 1? ek ser P t r \. e a & im a n alaa p ( M Scanned by CamScanner

Transcription:

Advancd Us f Pintrs CS2023 Wintr 2004

Outcms: Advancd us f Pintrs C fr Java Prgrammrs, Chaptr 8, sctin 8.11, 8.15 Othr txtbks n C n rsrv Aftr th cnclusin f this sctin yu shuld b abl t Allcat and dallcat blcks f mmry dynamically n th had Us pintrs t functins in rdr t pass a functin as a paramtr t anthr functin Us gnric pintrs t rit mr gnral functins

Dynamic Mmry Allcatin C's data structurs nrmally fixd in siz C supprts dynamic mmry allcatin t allcat strag during xcutin ndd fr dynamic arrays, lists, strings,... Dynamically allcatd mmry strd n th hap

Rcall: Mmry Managmnt Dynamically allcatd variabls Mmry allcatd and dstryd at run tim, undr cntrl f prgrammr! N guarant that first variabl t b dstryd is last cratd This ara f mmry can hav hls and is calld th hap

Rcall: Mmry Managmnt Usually hap and stack bgin at ppsit nds f th prgram's mmry, and gr tards ach thr

!!!!!! * #. ',, #, + Dynamic Mmry Allcatin Allcats a blck f mmry, but dsn't initializ it Allcats a blck f mmry and clars it and f typ, hich is typ rturnd by sizf pratr (nrmally ) " Nt: argumnts f $&% ')( $

2 < 21 80 6 21 E 2 < 80 6 2 < : I 3 3 80 6 J : 80 6 J G Dynamic Mmry Allcatin T primary mthds f allcating mmry: C&D < 1&; 1&; 9 : 354 :< A @<? 0 / <)= 1&; 9 : HG F A 0 3 8 :< A @<? 0 / <)= C&D < 1&; :< A @<? 1&; <)= D 35J C D C I 9 L 0 < 1 ; 9 :?M 0 4 K C&D C I 9 L 0 < 1&; 9N 8 K u shuld alays rmmbr t chck if a call t a mmry allcatin functin as succssful.

Dynamic Mmry Allcatin OP RS T U R V XW Z [ ] ^ P ^ O P R U O _` ` S a cb X X Z ` Od ^ _` O P a a gf h h ^i O ` kj ml n V l gh p j T R S a q r T OP Rs T U R c XW Z [ ] ^ t O P R U O _` ` s a cb X X Z ` t R Od ^ _` O P a a gf h h ^i O ` kj ml n V l gh p j T R s a u T 5 s

v ~ ƒ { } zy x Œ Š Ž Œ Š ˆ ~ ƒ v ~ ƒ { } zy ~œ { } zy Dynamic Mmry Allcatin Nt that mallc rturns vid*, hras th lft hand sid f is f typ. Sm prgrammrs us an xplicit cast, but this is nt rquird: { ~ & Š Alays pass rathr than th abslut valu us { { ~ š as a paramtr t mallc, instad f

Ÿ Ÿ ª ¹ µ ³ Ÿ ² Ã Ë Á Ã ÇÁ ÂÁ À À Mmry Dallcatin Mmry shuld b dallcatd nc th task it as allcatd fr has bn cmpltd. ž ± ± ž «³ º ± µ ¼» ½ ½ ½ ¾ É Â È Í Ì É&Ê È Å Æ Ä

Ñ Ð Ï Ï Î Ô Ó Ò Mmry Dallcatin Alays fll th call t ith Ô

ÚÙ Ø Ø Õ ÚÙ Ý ß ÜÛ â ç à é æ è î ì ì ç ï ð ø ý õ ÿ öü ôó ñ ò ø ý õ ÿ öü ôó ñ ò Errrs Mmry dallcatin using shuld nly b usd if mmry has bn prviusly allcatd ith : Ý Þ Ö& åæ ç àäã àá í æ êë alays rmmbr hr mmry cam frm: hap r stack Dn't crat garbag bjcts! úþ úû øù õö úþ úû øù õö Th first bjct cratd is n inaccssibl

Errrs Givn t pintrs and, th assignmnt nt cpy th blck f mmry pintd t by blck f mmry pintd t by ds int a Rmmbr that aftr if yu call yu must nt call ; and shar th valu; this uld als dallcat, n

! Pintrs t lcks Cntaining Pintrs A blck cntaining thr pintrs t dubl bjcts. In rdr t accss a singl bjct, th cd has t apply drfrncing tic blck 2.1 3.1 4.1

Pintrs t lcks Cntaining Pintrs "$# % '& ( ) ) '& # * +,. " ( /0 1 ( 23 54 6 0 / '& # * +98 :* ' ' # * 23 54 ; < 0 = #( / "$# % '& ( ) 8 8 @? A A C C CD E FHG I KJ L MON K P R TS N K U U V K F J WJ X G [Z K L ] X X G J^ _ ` K a Gb F cj G d W X b V V V L L f g g V ih i ij k l m l n qp sr t uv x k n qp yr z y{ z { t uv x k

ˆ ~ ƒ Œ Š Ž } ƒ œ š «š Pintrs t lcks Cntaining Pintrs Th cmplt cd t initializ th blck: Š Š ƒ } T fr mmry : žÿ œ œ ª œ œ

± ²³ µ ¹ º» ¼¾½ ³ À Á  ½ Ã Â±Ä Å Æ Ä ² Ç ÄÇ ½ È» º ³ ²É É Ã Â Ä Å ÆËÊ Å Â Â Ä Å É µ Ì Í ³ Î Ä ²É Ä Á à » Ï Ï Ï Ê Ê ÑÐ Ò Ò Ï ÔÓ Ô ÔÕ Ö Ø ÚÙ Û ÜÞÝ Ú ß àá ãâ Ý Ú ä ä å Ú Ö Ù æù ç è êé Ú ë Û ìè ç ç è ÚÙ ä íïî ð Ú ñ ò Ö óù ô æ ç ò å å å Û Û öõ å øù úù ù ûü þý ÿ ÿ þ ü û ý ûü ý þ ÿ ý ü û ý ÿ "! # " # $ % '& ' '( )* +,. / 01 23 4 * ) +5 6, 8 9;: 23 4 8 9<, =? A@ <, C +5 6 D 8 9 < D = 8, < D C 23 4 8 FE 5 G IH, IJ D J <

K [ XW P N UV [ XW TO P _ ] UV a f kj p sl r d d i v xy z ~ Pintrs t Functins A pintr t a functin dtrmins th prttyp f this functin, but it ds nt spcify its implmntatin: MU L N ^ M V LM U [P SZ TO S R OP U N ] N LM R LM MU L N ^ M V [P M ] N V S Z R P N LM ` ` ` u can assign an xisting functin t th pintr as lng as bth hav idntical paramtr lists and rturn typs: b h c d t p mn l gh bc ci h cq n u : {} thrugh th pintr u can call th functin ˆ ƒ ~

Œ ž Ÿ ž Ž Ÿ ž ««Functins as Paramtrs Œ Ž Ž Š ž ž œ Ž š Ž š Œ ž ž «ª;«Œ Ž ž ²± Ž «Ž

À À ¹» ¹ ½ µ ³ º ¾ º ÅÆ ¹ ½ ½Ä ¹ ¹ º º à  º È ÑÐ ÙØ Functins as Paramtrs µá» ¼» ¼ ¼» ¹º Ç Æ Æ» ¼» ¼ ¼» ¼ is calld: a virtual functin; its implmntatin is nt knn t but ill b prvidd hn is calld. ÉËÊ ÒËÓ Ì}Í Ô}Õ Î Ê Ö Ó ÉËÏ ÒË a callback functin, bcaus it calls back th functin supplid by th clint.

ÝÜ Þ ìß é á ê æ åä ãâ ï ìß í á ñ ô ï ì ãü âý âý ù ìß é á á ê æ åä ãâ ñ ô ìß ï ìß í í á ñ ñ ìß Gnric Sarch C ds nt supprt plymrphic prgramming, but it can b ). Û Ú simulatd using gnric pintrs (i.. A functin prttyp may spcify that a blck f mmry and th valu it is lking fr ar nt typd: ðòñ æ ïî í çè á â ßà êë à êæ à ã ö õ ã ä ë êë ã ßó â ã ßó â ø í á ã å ãÿ ä åä ü ã å êÿ ì þ ã ã õ ã ä ë áûú à ê à í ø ã ß ó â ã ß ó â ðòñ æ ïî í çè á â ßà êë à êæ à ã é ö á â êë à êæ ã åä ü ÿ êæ í é ßà ãõ ä ë êë ö ö í êë á â à êæ

Implmntatin f Gnric Sarch (incrrct)! " " # $ &% % % ' # (

Implmntatin f Gnric Sarch ) * +, /. 0 12 * 3 40 *, + 5 4 6) 98 4 0 :;, )< = +, )< ; 5 4 6) 5. 9 ;, ) < = + 9? ) < ; ) * + 3 40 A@ /. 3 40 *, + 5 4 6) ; 40 *, + 5 4 6) C 5 4 6) A D ) E 3 98 4 0 : F F HG I I / + / * J D E 4 / 3 A F 98 4 0 : D A K 98 4 0 : L, ) < 9? ) < D A L F 9? ) < ) E 3 40 A@ /. 3 A ; 5. 9 / + / * M D / + / * J D N

c b [Z [Z V UT SR ` f g c b V UT SR ` [Z [Z f g Applicatin f Gnric Sarch Th clint's rspnsibilitis: ]_a X S W ]_^ X S W O P P SR P SR ] a ] ^ Pd d X O X O ]_a W ] ^ W O P Sh P SR Sh P SR b a ] X S V ] b ^ ] X S V ] Pd d Nt that this callback is sufficint fr sarch, but nt fr srt.

ij kml l n qp r ts s u q v t x p y q x p z j i { u t }~ sƒ n j sƒ n ˆ Š t r uœ Œ q n n s p Œ }~ j y Ž s uœ sƒ n r Œ ~ ~k u s x Œ }~ š š ij t r q n Ž j i uœ y qp t uœ œ n u ž Ÿ u x Œ r Œ ~ ~k l x t r uœ œ u q y œ y ts s u r z q n ƒ y t y q x p z t Œ }~ ž y Ž s uœ sƒ n p s l t s r

NAME qsrt srts an array SNOPSIS #includ <stdlib.h vid qsrt(vid *bas, siz_t nmmb, siz_t siz, int(*cmpar)(cnst vid *, cnst vid *)); DESCRIPTION Th qsrt() functin srts an array ith nmmb lmnts f siz siz. Th bas argumnt pints t th start f th array. Th cntnts f th array ar srtd in ascnding rdr accrding t a cmparisn functin pintd t by cmpar, hich is calld ith t argumnts that pint t th bjcts bing cmpard. Th cmparisn functin must rturn an intgr lss than, qual t, r gratr than zr if th first argumnt is cnsidrd t b rspctivly lss than, qual t, r gratr than th scnd. If t mmbrs cmpar as qual, thir rdr in th srtd array is undfind.