\documentclass{beamer}
%
%
\makeatletter
\@ifundefined{lhs2tex.lhs2tex.sty.read}%
  {\@namedef{lhs2tex.lhs2tex.sty.read}{}%
   \newcommand\SkipToFmtEnd{}%
   \newcommand\EndFmtInput{}%
   \long\def\SkipToFmtEnd#1\EndFmtInput{}%
  }\SkipToFmtEnd

\newcommand\ReadOnlyOnce[1]{\@ifundefined{#1}{\@namedef{#1}{}}\SkipToFmtEnd}
\usepackage{amstext}
\usepackage{amssymb}
\usepackage{stmaryrd}
\DeclareFontFamily{OT1}{cmtex}{}
\DeclareFontShape{OT1}{cmtex}{m}{n}
  {<5><6><7><8>cmtex8
   <9>cmtex9
   <10><10.95><12><14.4><17.28><20.74><24.88>cmtex10}{}
\DeclareFontShape{OT1}{cmtex}{m}{it}
  {<-> ssub * cmtt/m/it}{}
\newcommand{\texfamily}{\fontfamily{cmtex}\selectfont}
\DeclareFontShape{OT1}{cmtt}{bx}{n}
  {<5><6><7><8>cmtt8
   <9>cmbtt9
   <10><10.95><12><14.4><17.28><20.74><24.88>cmbtt10}{}
\DeclareFontShape{OT1}{cmtex}{bx}{n}
  {<-> ssub * cmtt/bx/n}{}
\newcommand{\tex}[1]{\text{\texfamily#1}}	% NEU

\newcommand{\Sp}{\hskip.33334em\relax}
\newcommand{\NB}{\textbf{NB}}
\newcommand{\Todo}[1]{$\langle$\textbf{To do:}~#1$\rangle$}

\EndFmtInput
\makeatother
%
\author{Piyush P Kurur\\
  Office no: 224\\
  Dept. of Comp. Sci. and Engg.\\
  IIT Kanpur}


\newcommand{\Token}[2][]{\node(#2#1)[token]{#2};}
\newcommand{\Symbol}[2][]{\node(#2#1)[symbol]{#2};}
\newcommand{\Point}[1]{\node(#1)[point]{#1};}

\usepackage{tikz}
\usetikzlibrary{positioning,shapes,chains,fit}
\usetikzlibrary{shapes.symbols}
\usetikzlibrary{matrix}
\usetikzlibrary{backgrounds}
\usetikzlibrary{shapes.geometric}
\usepackage{multicol}

\usepackage{algorithm2e}
\usepackage{pgfkeys}

\pgfkeys {%
  /tikz/redbox/.style={%
    shape=rectangle,%
    minimum size=1.5em,%
    top color = white, %
    bottom color=red!50!black!50,
    inner sep=0pt,
    draw=black
  },
  /tikz/greybox/.style={ 
    shape=rectangle,%
    minimum width=7em,%
    minimum height=1.5em,
    fill=black!20,
    inner sep=0pt,
    draw=black
  },
  /tikz/blackbox/.style={ 
    shape=rectangle,%
    minimum width=7em,%
    minimum height=1.5em,
    fill=black,
    inner sep=0pt,
    draw=black
  },
  /tikz/whitebox/.style={
    shape=rectangle,
    minimum width=7em,
    minimum height=1.5em,
    draw=black
  },
  /tikz/bluebox/.style={
    shape=rectangle,
    minimum width=7em,
    minimum height=1.5em,
    fill=blue!40,
    draw=black
  },
  /tikz/whitetape/.style={
    shape=rectangle,
    minimum width=4em,
    minimum height=1.5em,
    draw=black
  },
  /tikz/bluearr/.style={
    ->,
    line width=0.25em, 
    draw=blue!40
  },
  /tikz/greenarr/.style={
    ->,
    line width=0.25em, 
    draw=green!40!black!60
  }
}

    
\newcommand{\arraythree}[4]{
  \begin{tikzpicture}[node distance=0]
    \pgfsetstrokeopacity{#4};
    \node[#1](a0#3){#2};
    \node[#1, right=of a0#3](a1#3){#2};
    \node[#1, right=of a1#3](a1#3){#2};
  \end{tikzpicture}
}

\newcommand{\arraytwo}[4]{
  \begin{tikzpicture}[node distance=0]
    \pgfsetstrokeopacity{#4};
    \node[#1](a0#3){#2};
    \node[#1,right=of a0#3]{#2};
  \end{tikzpicture}
}
  
\newcommand{\Array}[0]{
  \arraythree{box}{}{a}{1}
}

\newcommand{\AArray}[0]{%
  \arraythree{bbox}{\Array}{b}{0.5}}
\newcommand{\AAArray}[0]{%
  \arraytwo{bbbox}{\AArray}{c}{0.25}}


\newcommand{\T}[1]{\ensuremath{T\left(#1\right)}}  
\newcommand{\BigOh}[1]{\ensuremath{O\left(#1\right)}}
\title{Fundamentals of Computing: Lecture 24}
\date{September 25, 2009}
\begin{document}
\begin{frame}
  \maketitle
\end{frame}

\begin{frame}
  \frametitle{Structures}
  \pause
  \begin{tabbing}\tt
~~~~~\char35{}~line~170~\char34{}lecture23\char46{}lhs\char34{}\\
\tt ~~~\\
\tt ~~~~~struct~Vector2D\char123{}\\
\tt ~~~~~~~double~x\char59{}\\
\tt ~~~~~~~double~y\char59{}\\
\tt ~~~~~\char125{}\char59{}\\
\tt ~~~~~\\
\tt ~~~~~struct~Vector2D~origin~\char61{}~\char123{}0\char46{}0\char44{}0\char46{}0\char125{}\char59{}
\end{tabbing}

  This declares that Vector2D is a combination of 2 doubles.
  
  \pause
  \begin{block}{Accessing the fields}
    
    \begin{tabbing}\tt
~~~~~~~struct~Vector~v\char59{}\\
\tt ~~~~~~~printf\char40{}\char34{}v~is~the~vector~\char40{}\char37{}f\char44{}\char37{}f\char41{}\char34{}\char44{}~v\char46{}x\char44{}~v\char46{}y~\char41{}\char59{}
\end{tabbing}
  \end{block}
\end{frame}

\begin{frame}
  \frametitle{Fields are both l-values and r-values}
  \pause
  \begin{tabbing}\tt
~~~typedef~struct~Vector2D~Vector2D\char59{}\\
\tt ~~~~~Vector2D~addVector\char40{}Vector2D~u\char44{}~Vector2D~v\char41{}\\
\tt ~~~~~\char123{}\\
\tt ~~~~~~~Vector2D~w\char59{}\\
\tt ~~~~~~~w\char46{}x~\char61{}~u\char46{}x~\char43{}~v\char46{}x\char59{}\\
\tt ~~~~~~~w\char46{}y~\char61{}~u\char46{}y~\char43{}~v\char46{}y\char59{}\\
\tt ~~~~~~~return~w\char59{}\\
\tt ~~~~~\char125{}
\end{tabbing}
\end{frame}

\begin{frame}
  \frametitle{Java programmers please note}
  
  Structures are \emph{not} passed as reference to functions.
 \pause
  \begin{tabbing}\tt
~~~~~\char35{}line~214~\char34{}lecture23\char46{}lhs\char34{}\\
\tt ~~~~~\char35{}include~\char60{}stdio\char46{}h\char62{}\\
\tt ~~~~~void~printVector\char40{}struct~Vector2D\char41{}\char59{}\\
\tt ~~~~~void~shiftByOneUnit\char40{}struct~Vector2D~u\char41{}\char59{}\\
\tt ~~~~~int~main~\char40{}\char41{}~\char123{}\\
\tt ~~~~~~~printf\char40{}\char34{}Before~shift\char58{}~\char34{}\char41{}\char59{}printVector\char40{}origin\char41{}\char59{}\\
\tt ~~~~~~~shiftByOneUnit\char40{}origin\char41{}\char59{}\\
\tt ~~~~~~~printf\char40{}\char34{}After~shift\char58{}~\char34{}\char41{}\char59{}printVector\char40{}origin\char41{}\char59{}\\
\tt ~~~~~\char125{}\\
\tt ~~~~~void~shiftByOneUnit\char40{}struct~Vector2D~u\char41{}\char123{}\\
\tt ~~~~~~~u\char46{}x~\char61{}~u\char46{}x~\char43{}~1\char59{}\\
\tt ~~~~~\char125{}\\
\tt ~~~~~void~printVector\char40{}struct~Vector2D~u\char41{}\char123{}\\
\tt ~~~~~~~printf\char40{}\char34{}\char40{}\char37{}f\char44{}\char37{}f\char41{}\char92{}n\char34{}\char44{}u\char46{}x\char44{}u\char46{}y\char41{}\char59{}\\
\tt ~~~~~\char125{}
\end{tabbing}
\end{frame}

\end{document}

\begin{frame}
  \begin{block}{Syntax}
    \begin{tabbing}\tt
~~~~~~~struct~name~\char123{}\\
\tt ~~~~~~~~~declarations\char59{}~\char47{}\char42{}~field~declarations~\char42{}\char47{}\\
\tt ~~~~~~~\char125{}\char59{}
\end{tabbing}
  \end{block}
  \pause
  \begin{itemize}
  \item There should be no recursive definition, however
    \pause
  \item A structure Foo can have as field member a pointer to Foo.
  \end{itemize}
\end{frame}

\begin{frame}
  \frametitle{Abstract data type List}
  \pause
  A list is either
  \begin{itemize}
  \item An empty list
    or
    \pause
  \item A starting element, called the head of the list, followed by a
    list of integers, called the tail.
  \end{itemize}

  \pause

  \begin{tabbing}\tt
~~~~~data~List~\char61{}~EmptyList~\char124{}~Node~Int~List
\end{tabbing}

  \pause

  Things are not so clean in \text{\tt C}
  \pause
  \begin{tabbing}\tt
~~~~~typedef~struct~Node~Node\char59{}\\
\tt ~~~~~struct~Node~\char123{}\\
\tt ~~~~~~~int~datum\char59{}\\
\tt ~~~~~~~struct~Node~\char42{}next\char59{}\\
\tt ~~~~~\char125{}\char59{}\\
\tt ~~~~~typedef~Node~\char42{}~List\char59{}\\
\tt ~~~~~Node~emptyNode~\char61{}~\char123{}0\char44{}~NULL\char125{}\char59{}\\
\tt ~~~~~List~emptyList~\char61{}~\char38{}emptyNode\char59{}
\end{tabbing}

\end{frame}


