pointer zuerst
beispiel verkette listen
This commit is contained in:
		
							
								
								
									
										244
									
								
								src/main.tex
									
									
									
									
									
								
							
							
						
						
									
										244
									
								
								src/main.tex
									
									
									
									
									
								
							@@ -71,101 +71,6 @@
 | 
				
			|||||||
        \maketitle % Automatically created using the information in the commands above
 | 
					        \maketitle % Automatically created using the information in the commands above
 | 
				
			||||||
    \end{frame}
 | 
					    \end{frame}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
%----------------------------------------------------------------------------------------
 | 
					 | 
				
			||||||
%	 SECTION 1
 | 
					 | 
				
			||||||
%----------------------------------------------------------------------------------------
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    \section{Strukturen} % Section title slide, unnumbered
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
%------------------------------------------------
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    \begin{frame}{Strukturen Allgemein}
 | 
					 | 
				
			||||||
        \input{structallg.tex}
 | 
					 | 
				
			||||||
    \end{frame}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
%------------------------------------------------
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    \begin{frame}[fragile, allowframebreaks]{C Syntax}
 | 
					 | 
				
			||||||
        Definition:
 | 
					 | 
				
			||||||
        \begin{lstlisting}
 | 
					 | 
				
			||||||
struct Adresse {
 | 
					 | 
				
			||||||
    char name[50];
 | 
					 | 
				
			||||||
	char strasse[100];
 | 
					 | 
				
			||||||
	short hausnummer;
 | 
					 | 
				
			||||||
	long plz;
 | 
					 | 
				
			||||||
	char stadt[50];
 | 
					 | 
				
			||||||
};
 | 
					 | 
				
			||||||
        \end{lstlisting}
 | 
					 | 
				
			||||||
        Anwendung:
 | 
					 | 
				
			||||||
        \begin{lstlisting}
 | 
					 | 
				
			||||||
// Variable der Struktur erstellen
 | 
					 | 
				
			||||||
struct Adresse adresseKurt;
 | 
					 | 
				
			||||||
// Zugriff auf die Elemente
 | 
					 | 
				
			||||||
strcpy(adresseKurt.name, "Kurt Kanns");
 | 
					 | 
				
			||||||
adresseKurt.hausnummer = 23;
 | 
					 | 
				
			||||||
adresseKurt.plz = 45678;
 | 
					 | 
				
			||||||
        \end{lstlisting}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        \framebreak
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        Typdefinition mit typedef:
 | 
					 | 
				
			||||||
        \begin{lstlisting}
 | 
					 | 
				
			||||||
typedef struct Adresse {
 | 
					 | 
				
			||||||
    char name[50];
 | 
					 | 
				
			||||||
	short hausnummer;
 | 
					 | 
				
			||||||
} ADR;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
ADR a1,a2;
 | 
					 | 
				
			||||||
        \end{lstlisting}
 | 
					 | 
				
			||||||
    \end{frame}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    \begin{frame}{Sonstiges}
 | 
					 | 
				
			||||||
        \begin{itemize}
 | 
					 | 
				
			||||||
            \item Strukturtypdeklaration: struct Adresse {…};
 | 
					 | 
				
			||||||
            \item Gesamtlänge der Struktur: sizeof(Struktur)
 | 
					 | 
				
			||||||
            \item Zugriff auf einzelne Komponenten durch\\
 | 
					 | 
				
			||||||
            Punktnotation: Adresse1.Vorname = “Peter“;
 | 
					 | 
				
			||||||
            \item Weitere Strukturen hinzufügen: struct Adresse Adresse5;
 | 
					 | 
				
			||||||
            \item Weiteres hinzufügen von Komponenten während der Laufzeit nicht möglich.
 | 
					 | 
				
			||||||
        \end{itemize}
 | 
					 | 
				
			||||||
    \end{frame}
 | 
					 | 
				
			||||||
%------------------------------------------------
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    \begin{frame}[fragile]{Strukturen als Funktionsargument}
 | 
					 | 
				
			||||||
        Ohne Typedef:
 | 
					 | 
				
			||||||
        \begin{lstlisting}
 | 
					 | 
				
			||||||
void testfunc(struct Adresse a){
 | 
					 | 
				
			||||||
    long plz = a.plz;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
        \end{lstlisting}
 | 
					 | 
				
			||||||
        Mit Typedef:
 | 
					 | 
				
			||||||
        \begin{lstlisting}
 | 
					 | 
				
			||||||
void testfunc(ADR a){
 | 
					 | 
				
			||||||
    long plz = a.plz;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
        \end{lstlisting}
 | 
					 | 
				
			||||||
    \end{frame}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
%------------------------------------------------
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    \begin{frame}[fragile]{Strukturen in Java}
 | 
					 | 
				
			||||||
        \begin{itemize}
 | 
					 | 
				
			||||||
            \item existieren nicht
 | 
					 | 
				
			||||||
            \item stattdessen Objekte
 | 
					 | 
				
			||||||
        \end{itemize}
 | 
					 | 
				
			||||||
        \begin{lstlisting}[language=java]
 | 
					 | 
				
			||||||
public class Adresse
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
    String name;
 | 
					 | 
				
			||||||
	String strasse;
 | 
					 | 
				
			||||||
	short hausnummer;
 | 
					 | 
				
			||||||
	long plz;
 | 
					 | 
				
			||||||
	String stadt;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
        \end{lstlisting}
 | 
					 | 
				
			||||||
    \end{frame}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
%----------------------------------------------------------------------------------------
 | 
					%----------------------------------------------------------------------------------------
 | 
				
			||||||
%	 SECTION 2
 | 
					%	 SECTION 2
 | 
				
			||||||
%----------------------------------------------------------------------------------------
 | 
					%----------------------------------------------------------------------------------------
 | 
				
			||||||
@@ -208,7 +113,7 @@ int main()
 | 
				
			|||||||
   //Assigning address of num to the pointer p
 | 
					   //Assigning address of num to the pointer p
 | 
				
			||||||
   p = *num;
 | 
					   p = *num;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
   printf("Address of variable: %p", p);
 | 
					   printf("Num: %d", &p);
 | 
				
			||||||
   return 0;
 | 
					   return 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
        \end{lstlisting}
 | 
					        \end{lstlisting}
 | 
				
			||||||
@@ -217,6 +122,153 @@ int main()
 | 
				
			|||||||
%------------------------------------------------
 | 
					%------------------------------------------------
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    \begin{frame}{Pointer in Java}
 | 
					    \begin{frame}{Pointer in Java}
 | 
				
			||||||
 | 
					        \begin{itemize}
 | 
				
			||||||
 | 
					            \item Alle Objekte automatisch Pointer
 | 
				
			||||||
 | 
					            \item Primitives (int, float, double) sind Wert direkt
 | 
				
			||||||
 | 
					        \end{itemize}
 | 
				
			||||||
 | 
					    \end{frame}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					%----------------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					%	 SECTION 2
 | 
				
			||||||
 | 
					%----------------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    \section{Strukturen} % Section title slide, unnumbered
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					%------------------------------------------------
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    \begin{frame}{Strukturen Allgemein}
 | 
				
			||||||
 | 
					        \begin{itemize}
 | 
				
			||||||
 | 
					            \item kategorisieren von Variablen
 | 
				
			||||||
 | 
					            \begin{itemize}
 | 
				
			||||||
 | 
					                \item Variablen \textit{(int, char, double, float)}
 | 
				
			||||||
 | 
					                \item Pointer
 | 
				
			||||||
 | 
					                \item Arrays
 | 
				
			||||||
 | 
					            \end{itemize}
 | 
				
			||||||
 | 
					            \item Keyword \textit{struct}
 | 
				
			||||||
 | 
					            \pause
 | 
				
			||||||
 | 
					            \item verbessert Übersicht
 | 
				
			||||||
 | 
					            \item Schritt richtung Objektorientierung
 | 
				
			||||||
 | 
					            \item ideal für Listen und Baumstruktur
 | 
				
			||||||
 | 
					        \end{itemize}
 | 
				
			||||||
 | 
					    \end{frame}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					%------------------------------------------------
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    \begin{frame}[fragile, allowframebreaks]{C Syntax}
 | 
				
			||||||
 | 
					        Definition:
 | 
				
			||||||
 | 
					        \begin{lstlisting}
 | 
				
			||||||
 | 
					struct Adresse {
 | 
				
			||||||
 | 
					    char name[50];
 | 
				
			||||||
 | 
						int *nummer;
 | 
				
			||||||
 | 
						short hausnummer;
 | 
				
			||||||
 | 
						long plz;
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					        \end{lstlisting}
 | 
				
			||||||
 | 
					        Anwendung:
 | 
				
			||||||
 | 
					        \begin{lstlisting}
 | 
				
			||||||
 | 
					// Variable der Struktur erstellen
 | 
				
			||||||
 | 
					struct Adresse adresseKurt;
 | 
				
			||||||
 | 
					// Zugriff auf die Elemente
 | 
				
			||||||
 | 
					strcpy(adresseKurt.name, "Kurt Kanns");
 | 
				
			||||||
 | 
					adresseKurt.hausnummer = 23;
 | 
				
			||||||
 | 
					adresseKurt->nummer = 4;
 | 
				
			||||||
 | 
					adresseKurt.plz = 45678;
 | 
				
			||||||
 | 
					        \end{lstlisting}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        \framebreak
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        Typdefinition mit typedef:
 | 
				
			||||||
 | 
					        \begin{lstlisting}
 | 
				
			||||||
 | 
					typedef struct Adresse {
 | 
				
			||||||
 | 
					    char name[50];
 | 
				
			||||||
 | 
						short hausnummer;
 | 
				
			||||||
 | 
					} ADR;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					ADR a1,a2;
 | 
				
			||||||
 | 
					        \end{lstlisting}
 | 
				
			||||||
 | 
					    \end{frame}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    \begin{frame}{Sonstiges}
 | 
				
			||||||
 | 
					        \begin{itemize}
 | 
				
			||||||
 | 
					            \item Strukturtypdeklaration: struct Adresse \{…\};
 | 
				
			||||||
 | 
					            \item Gesamtlänge der Struktur: sizeof(Struktur)
 | 
				
			||||||
 | 
					            \item Zugriff auf einzelne Komponenten durch\\
 | 
				
			||||||
 | 
					            Punktnotation: Adresse1.Vorname = “Peter“;
 | 
				
			||||||
 | 
					            \item Pfeilnotation (->) wenn Komponente ist Pointer
 | 
				
			||||||
 | 
					            \item Weiteres hinzufügen von Komponenten während der Laufzeit nicht möglich.
 | 
				
			||||||
 | 
					        \end{itemize}
 | 
				
			||||||
 | 
					    \end{frame}
 | 
				
			||||||
 | 
					%------------------------------------------------
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    \begin{frame}[fragile]{Strukturen als Funktionsargument}
 | 
				
			||||||
 | 
					        Ohne Typedef:
 | 
				
			||||||
 | 
					        \begin{lstlisting}
 | 
				
			||||||
 | 
					void testfunc(struct Adresse a){
 | 
				
			||||||
 | 
					    long plz = a.plz;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					        \end{lstlisting}
 | 
				
			||||||
 | 
					        Mit Typedef:
 | 
				
			||||||
 | 
					        \begin{lstlisting}
 | 
				
			||||||
 | 
					void testfunc(ADR a){
 | 
				
			||||||
 | 
					    long plz = a.plz;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					        \end{lstlisting}
 | 
				
			||||||
 | 
					    \end{frame}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					%------------------------------------------------
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    \begin{frame}[fragile]{Strukturen in Java}
 | 
				
			||||||
 | 
					        \begin{itemize}
 | 
				
			||||||
 | 
					            \item existieren nicht
 | 
				
			||||||
 | 
					            \item stattdessen Objekte
 | 
				
			||||||
 | 
					        \end{itemize}
 | 
				
			||||||
 | 
					        \begin{lstlisting}[language=java]
 | 
				
			||||||
 | 
					public class Adresse
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    String name;
 | 
				
			||||||
 | 
						String strasse;
 | 
				
			||||||
 | 
						short hausnummer;
 | 
				
			||||||
 | 
						long plz;
 | 
				
			||||||
 | 
						String stadt;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					        \end{lstlisting}
 | 
				
			||||||
 | 
					    \end{frame}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					%----------------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					%	 SECTION 3
 | 
				
			||||||
 | 
					%----------------------------------------------------------------------------------------
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    \section{Anwendung} % Section title slide, unnumbered
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					%------------------------------------------------
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    \begin{frame}[fragile]{Verkettete Listen}
 | 
				
			||||||
 | 
					        \begin{lstlisting}
 | 
				
			||||||
 | 
					struct node {
 | 
				
			||||||
 | 
					   int data;
 | 
				
			||||||
 | 
					   struct node* next;
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					typedef struct node  node;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void beispiel() {
 | 
				
			||||||
 | 
					   // Erstellen von root
 | 
				
			||||||
 | 
					   node *root = malloc(sizeof(node));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   root.data = 17;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   // Anhaengen eines Knotens
 | 
				
			||||||
 | 
					   node *secondNode = malloc(sizeof(node));
 | 
				
			||||||
 | 
					   root->next = secondNode;
 | 
				
			||||||
 | 
					   secondNode.data = 19;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					        \end{lstlisting}
 | 
				
			||||||
 | 
					    \end{frame}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					%------------------------------------------------
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    \begin{frame}[fragile]{Struktur als Pointer}
 | 
				
			||||||
        todo
 | 
					        todo
 | 
				
			||||||
    \end{frame}
 | 
					    \end{frame}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,13 +0,0 @@
 | 
				
			|||||||
\begin{itemize}
 | 
					 | 
				
			||||||
    \item kategorisieren von Variablen
 | 
					 | 
				
			||||||
    \begin{itemize}
 | 
					 | 
				
			||||||
        \item Variablen \textit{(int, char, double, float)}
 | 
					 | 
				
			||||||
        \item Pointer
 | 
					 | 
				
			||||||
        \item Arrays
 | 
					 | 
				
			||||||
    \end{itemize}
 | 
					 | 
				
			||||||
    \item Keyword \textit{struct}
 | 
					 | 
				
			||||||
    \pause
 | 
					 | 
				
			||||||
    \item verbessert Übersicht
 | 
					 | 
				
			||||||
    \item Schritt richtung Objektorientierung
 | 
					 | 
				
			||||||
    \item ideal für Listen und Baumstruktur
 | 
					 | 
				
			||||||
\end{itemize}
 | 
					 | 
				
			||||||
		Reference in New Issue
	
	Block a user