SlideShare uma empresa Scribd logo
1 de 30
Baixar para ler offline
Chapter 1
Data Structures
Assoc. Prof. Dr. Oğuz FINDIK
2016-2017
KBUZEM
KARABUK UNIVERSITY
1
 Referencess Books
 A book on C All KELLEY, İra POHL
 Data Structures and Program Design in C++ By Robert L.
Kruse and Alexander J Ryba
Referencess Book
2
 You can not do anything without data on world . İf you want to
proceed add operator, you should have at least two number.
 Computer sciences deal with storing, organizing and retrieving
effectively of data.
 Computer programmer should get data from user or another
sources and use them.
 for this purpose you have to use data structure for every software
program or system.
Why data structures is important for
computer engineering?
3
 WE will use eclipse IDE for developing program in this course.
 Steps to install Eclipse and run
 Download eclipse Neon from
http://www.eclipse.org/downloads/
 Choose Eclipse IDE for C/C++ Developers and install
 You should download and install MinGW GCC
http://www.mingw.org/
Eclipse
4
 Functions break large computing tasks into smaller
ones.
 Taking a problem and breaking into small,
manageable pieces is ritical to writing large programs.
 So important definition for function,
 Functions return values to where is invoked.
C programming
5
 Function definition
 type function_name(parameter list ) {declerations
statements}
 The parameter list is a comma-seperated list of declarations.
Functions
6
Example
7
Scope of Variables
8
 return; // return ++a; // return (a*b)
 When a return statement is encountered, execution of the
function is terminated and control is passed back to calling
environment. İf the return statement contains an expression,
then the value of the expressions is passed to the calling
environment as well.
Return Statement
9
Example
10
 Every variable and function in C has two attributes.
Type and storage class. Four storage classes are
automatics, external, register and static with
corresponding
 auto extern register static
Storage Classes
11
 Storage class auto:
 Variables declared within function are automatic by default.
These variables can be used in scope of the function.
 Storage class extern:
 One methods of transmitting information across blocks and
functions is to use external variables. When a variable is
declared outside a function, storage is permanently assigned
to it, and its storage class is extern.
Storage Classes
12
 #include <stdio.h>
 extern int a = 1, b = 2;
 c = 3;
 int f(void);
 int main(void) {
 printf("%3dn", f());
 printf("%3d%3d%3dn", a, b, c);
 return 0;
 }
 int f(void) {
 auto int b, c;
 a = b = c = 4;
 return (a + b + c);
 }
Example
13
file2.c
int f(void) {
extern a;
int b, c;
b = c = a;
return (a + b +
c);
}
Extern keyword
 This use of extern is used to tell the
compiler to ‘’look for it elsewhere’’ either
in this file or in some other file.
Örnek1.c
#include <stdio.h>
int a = 1, b = 2;
c = 3;
int f(void);
int main(void) {
printf("%3dn", f());
printf("%3d%3d%3dn", a, b, c);
return 0;
} 14
 Storage class register tells the compiler that the association
variables should be stored in high-speed memory registers.
#include <stdio.h>
#include <time.h>
int a =1;
#define N 10000
int main(void) {
clock_t start, end;
double cpu_time_used;
register double i;
start = clock();
for(i=0;i<N;i=i+0.0001);
end = clock();
cpu_time_used = ((double) (end - start)) / CLOCKS_PER_SEC;
printf("Running time is %f",cpu_time_used);
return 0;
}
Storage Class Register
 Running
time is
0,163
second
with
register
variable.
 Running
time is
0,419
second
without
register
variable.
15
 Static declarations have two important and distinct
uses. One of them is to allow a local variable to retain its
previous value when the block is reentered.
Storage class static
16
 The second and more subtle use of static is in connection with
external declarations. İt is use to restriction of the scope of
the variable.
Storage class static
17
 A typical memory
representation of C program
consists of following sections.
 1. Text segment
2. Initialized data segment
3. Uninitialized data segment
4. Stack
5. Heap
18
Memory Layout of C Programs
 1. Text Segment:
 A text segment , also known as a code segment or simply as
text, is one of the sections of a program in an object file or in
memory, which contains executable instructions.
 Usually, the text segment is sharable so that only a single
copy needs to be in memory for frequently executed
programs, such as text editors, the C compiler, the shells,
and so on. Also, the text segment is often read-only, to
prevent a program from accidentally modifying its
instructions. 19
Memory Layout of C Programs
 2. Initialized Data Segment: A data segment is a portion of
virtual address space of a program, which contains the global
variables and static variables that are initialized by the
programmer.
 3. Uninitialized Data Segment:Data in this segment is
initialized by the kernel to arithmetic 0 before the program
starts executing uninitialized data starts at the end of the
data segment and contains all global variables and static
variables that are initialized to zero or do not have explicit
initialization in source code.
20
Memory Layout of C Programs
 4. Stack:
 Stack, where automatic variables are stored, along with
information that is saved each time a function is called. Each
time a function is called, the address of where to return to
and certain information about the caller’s environment, such
as some of the machine registers, are saved on the stack. The
newly called function then allocates room on the stack for its
automatic and temporary variables.
 This is how recursive functions in C can work. Each time a
recursive function calls itself, a new stack frame is used, so
one set of variables doesn’t interfere with the variables from
another instance of the function.
21
Memory Layout of C Programs
 5. Heap:
 Heap is the segment where dynamic memory allocation
usually takes place.
 Heap area is managed by malloc, realloc, and free.
22
Memory Layout of C Programs
#include <stdio.h>
int global; /* Uninitialized variable stored in bss*/
int main(void)
{
int *ptr_one;
ptr_one = (int *)malloc(sizeof(int));
int c;//stack
static int i = 100; /* Initialized static variable stored in DS*/
return 0;
}
23
Example
 A function is said to be recursive if it class itself
directly or indirectly. in C, all functions can be used
recursively, including main function.
Recursion
24
Examples
25
 Typically, a large program is written in a separate
directory as a collection of .h and .c file, with each .c
file contains one or more functions definition
 When preprocessor encounters #include "pgm.h«
directive search this file in the same directory or
system-dependent places. İf it cannot be found,
preprocessor issues an error message and
compilations stops.
Developing Large Program
26
 .h files contain #includes, #defines, templates of enumaration
types, templates of structure and union types, and list of
function prototype at the bottom.
 pgm.h file:
 #include <stdio.h>
 #include <stdlib.h>
 #define N 3
 void fct1(int k);
 void fct2(void);
 void wrt_info(char *);
Developing Large Program
27
 fct.c file
 #include "pgm.h"
 void fct1(int n)
 {
 int i;
 printf("Hello from fct1()n");
 for(i=0;i<n;++i)
 fct2();
 }
 void fct2(void){
 printf("Hello from fct2()n");
 }
Example
28
 wrt.c file:
 #include "pgm.h"
 void wrt_info(char
*pgm_name){
 printf("Usage:
%snn",pgm_name);
 printf("%sn",
 "Hello from wrt_info-1n"
 "Hello from wrt_info-2n"
 "Hello from wrt_info-3n");
 }
Example
 main.c file:
 #include "pgm.h"
 int main(void) {
 char ans;
 int i, n = N;
 printf("%s", "This program does not do very much.n
"
 "Do you want to more
information?");
 fflush(stdout);
 scanf("%c", &ans);
 if (ans == 'y' || ans == 'Y')
 wrt_info("pgm");
 for (i = 0; i < n; ++i)
 fct1(i);
 printf("Bye!n");
 return 0;
 }
 }
29
Tower of Hanoi
 Write c code that
solves this problem.
You have to use
recursive function.
30

Mais conteúdo relacionado

Mais procurados

OOP in C - Inherit (Chinese Version)
OOP in C - Inherit (Chinese Version)OOP in C - Inherit (Chinese Version)
OOP in C - Inherit (Chinese Version)Kai-Feng Chou
 
Solid C++ by Example
Solid C++ by ExampleSolid C++ by Example
Solid C++ by ExampleOlve Maudal
 
Paradigmas de Linguagens de Programacao - Aula #4
Paradigmas de Linguagens de Programacao - Aula #4Paradigmas de Linguagens de Programacao - Aula #4
Paradigmas de Linguagens de Programacao - Aula #4Ismar Silveira
 
Pointers Refrences & dynamic memory allocation in C++
Pointers Refrences & dynamic memory allocation in C++Pointers Refrences & dynamic memory allocation in C++
Pointers Refrences & dynamic memory allocation in C++Gamindu Udayanga
 
Dynamic memory allocation
Dynamic memory allocationDynamic memory allocation
Dynamic memory allocationGem WeBlog
 
Function in c language(defination and declaration)
Function in c language(defination and declaration)Function in c language(defination and declaration)
Function in c language(defination and declaration)VC Infotech
 
Function pointer
Function pointerFunction pointer
Function pointerGem WeBlog
 
ฟังก์ชั่นย่อยและโปรแกรมมาตรฐาน ม. 6 1
ฟังก์ชั่นย่อยและโปรแกรมมาตรฐาน ม. 6  1ฟังก์ชั่นย่อยและโปรแกรมมาตรฐาน ม. 6  1
ฟังก์ชั่นย่อยและโปรแกรมมาตรฐาน ม. 6 1Little Tukta Lita
 
李建忠、侯捷设计模式讲义
李建忠、侯捷设计模式讲义李建忠、侯捷设计模式讲义
李建忠、侯捷设计模式讲义yiditushe
 
Pointers and Structures
Pointers and StructuresPointers and Structures
Pointers and StructuresGem WeBlog
 
OOP in C - Before GObject (Chinese Version)
OOP in C - Before GObject (Chinese Version)OOP in C - Before GObject (Chinese Version)
OOP in C - Before GObject (Chinese Version)Kai-Feng Chou
 
An imperative study of c
An imperative study of cAn imperative study of c
An imperative study of cTushar B Kute
 
C Programming Storage classes, Recursion
C Programming Storage classes, RecursionC Programming Storage classes, Recursion
C Programming Storage classes, RecursionSreedhar Chowdam
 
C++ idioms by example (Nov 2008)
C++ idioms by example (Nov 2008)C++ idioms by example (Nov 2008)
C++ idioms by example (Nov 2008)Olve Maudal
 
1 introducing c language
1  introducing c language1  introducing c language
1 introducing c languageMomenMostafa
 
Fpga 06-data-types-system-tasks-compiler-directives
Fpga 06-data-types-system-tasks-compiler-directivesFpga 06-data-types-system-tasks-compiler-directives
Fpga 06-data-types-system-tasks-compiler-directivesMalik Tauqir Hasan
 

Mais procurados (20)

OOP in C - Inherit (Chinese Version)
OOP in C - Inherit (Chinese Version)OOP in C - Inherit (Chinese Version)
OOP in C - Inherit (Chinese Version)
 
Solid C++ by Example
Solid C++ by ExampleSolid C++ by Example
Solid C++ by Example
 
Paradigmas de Linguagens de Programacao - Aula #4
Paradigmas de Linguagens de Programacao - Aula #4Paradigmas de Linguagens de Programacao - Aula #4
Paradigmas de Linguagens de Programacao - Aula #4
 
Pointers Refrences & dynamic memory allocation in C++
Pointers Refrences & dynamic memory allocation in C++Pointers Refrences & dynamic memory allocation in C++
Pointers Refrences & dynamic memory allocation in C++
 
Dynamic memory allocation
Dynamic memory allocationDynamic memory allocation
Dynamic memory allocation
 
Function in c language(defination and declaration)
Function in c language(defination and declaration)Function in c language(defination and declaration)
Function in c language(defination and declaration)
 
Function pointer
Function pointerFunction pointer
Function pointer
 
ฟังก์ชั่นย่อยและโปรแกรมมาตรฐาน ม. 6 1
ฟังก์ชั่นย่อยและโปรแกรมมาตรฐาน ม. 6  1ฟังก์ชั่นย่อยและโปรแกรมมาตรฐาน ม. 6  1
ฟังก์ชั่นย่อยและโปรแกรมมาตรฐาน ม. 6 1
 
李建忠、侯捷设计模式讲义
李建忠、侯捷设计模式讲义李建忠、侯捷设计模式讲义
李建忠、侯捷设计模式讲义
 
Pointers and Structures
Pointers and StructuresPointers and Structures
Pointers and Structures
 
C Programming Tutorial - www.infomtec.com
C Programming Tutorial - www.infomtec.comC Programming Tutorial - www.infomtec.com
C Programming Tutorial - www.infomtec.com
 
Unit 3 (1)
Unit 3 (1)Unit 3 (1)
Unit 3 (1)
 
OOP in C - Before GObject (Chinese Version)
OOP in C - Before GObject (Chinese Version)OOP in C - Before GObject (Chinese Version)
OOP in C - Before GObject (Chinese Version)
 
An imperative study of c
An imperative study of cAn imperative study of c
An imperative study of c
 
C Programming Storage classes, Recursion
C Programming Storage classes, RecursionC Programming Storage classes, Recursion
C Programming Storage classes, Recursion
 
Python Programming
Python ProgrammingPython Programming
Python Programming
 
C++ idioms by example (Nov 2008)
C++ idioms by example (Nov 2008)C++ idioms by example (Nov 2008)
C++ idioms by example (Nov 2008)
 
1 introducing c language
1  introducing c language1  introducing c language
1 introducing c language
 
Fpga 06-data-types-system-tasks-compiler-directives
Fpga 06-data-types-system-tasks-compiler-directivesFpga 06-data-types-system-tasks-compiler-directives
Fpga 06-data-types-system-tasks-compiler-directives
 
Lecture 8- Data Input and Output
Lecture 8- Data Input and OutputLecture 8- Data Input and Output
Lecture 8- Data Input and Output
 

Semelhante a Data structure week 1

Basic construction of c
Basic construction of cBasic construction of c
Basic construction of ckinish kumar
 
Unit 5 quesn b ans5
Unit 5 quesn b ans5Unit 5 quesn b ans5
Unit 5 quesn b ans5Sowri Rajan
 
C, C++ Interview Questions Part - 1
C, C++ Interview Questions Part - 1C, C++ Interview Questions Part - 1
C, C++ Interview Questions Part - 1ReKruiTIn.com
 
Presentation on Function in C Programming
Presentation on Function in C ProgrammingPresentation on Function in C Programming
Presentation on Function in C ProgrammingShuvongkor Barman
 
6 preprocessor macro header
6 preprocessor macro header6 preprocessor macro header
6 preprocessor macro headerhasan Mohammad
 
Interoduction to c++
Interoduction to c++Interoduction to c++
Interoduction to c++Amresh Raj
 
Storage_classes_and_Scope_rules.pptx
Storage_classes_and_Scope_rules.pptxStorage_classes_and_Scope_rules.pptx
Storage_classes_and_Scope_rules.pptxCheriviralaNikhil
 
Basic structure of c programming
Basic structure of c programmingBasic structure of c programming
Basic structure of c programmingTejaswiB4
 
Basic structure of c programming
Basic structure of c programmingBasic structure of c programming
Basic structure of c programmingTejaswiB4
 
Book management system
Book management systemBook management system
Book management systemSHARDA SHARAN
 
Unit 5 quesn b ans5
Unit 5 quesn b ans5Unit 5 quesn b ans5
Unit 5 quesn b ans5Sowri Rajan
 

Semelhante a Data structure week 1 (20)

C++ Constructs.pptx
C++ Constructs.pptxC++ Constructs.pptx
C++ Constructs.pptx
 
Storage classes in C
Storage classes in CStorage classes in C
Storage classes in C
 
Basic construction of c
Basic construction of cBasic construction of c
Basic construction of c
 
Embedded C.pptx
Embedded C.pptxEmbedded C.pptx
Embedded C.pptx
 
Unit 5 quesn b ans5
Unit 5 quesn b ans5Unit 5 quesn b ans5
Unit 5 quesn b ans5
 
C, C++ Interview Questions Part - 1
C, C++ Interview Questions Part - 1C, C++ Interview Questions Part - 1
C, C++ Interview Questions Part - 1
 
Presentation on Function in C Programming
Presentation on Function in C ProgrammingPresentation on Function in C Programming
Presentation on Function in C Programming
 
Cpp
CppCpp
Cpp
 
Structure of the C Program.docx
Structure of the C Program.docxStructure of the C Program.docx
Structure of the C Program.docx
 
6 preprocessor macro header
6 preprocessor macro header6 preprocessor macro header
6 preprocessor macro header
 
Interoduction to c++
Interoduction to c++Interoduction to c++
Interoduction to c++
 
Storage_classes_and_Scope_rules.pptx
Storage_classes_and_Scope_rules.pptxStorage_classes_and_Scope_rules.pptx
Storage_classes_and_Scope_rules.pptx
 
Basic structure of c programming
Basic structure of c programmingBasic structure of c programming
Basic structure of c programming
 
Basic structure of c programming
Basic structure of c programmingBasic structure of c programming
Basic structure of c programming
 
C programming session9 -
C programming  session9 -C programming  session9 -
C programming session9 -
 
Programming in C
Programming in CProgramming in C
Programming in C
 
Storage class
Storage classStorage class
Storage class
 
Book management system
Book management systemBook management system
Book management system
 
Memory management in c++
Memory management in c++Memory management in c++
Memory management in c++
 
Unit 5 quesn b ans5
Unit 5 quesn b ans5Unit 5 quesn b ans5
Unit 5 quesn b ans5
 

Mais de karmuhtam

Devre analizi deney malzeme listesi
Devre analizi deney malzeme listesiDevre analizi deney malzeme listesi
Devre analizi deney malzeme listesikarmuhtam
 
Deney 3 ve 4
Deney 3 ve 4Deney 3 ve 4
Deney 3 ve 4karmuhtam
 
Deney 1 ve 2
Deney 1 ve 2Deney 1 ve 2
Deney 1 ve 2karmuhtam
 
Data structure week y 5 1
Data structure week y 5 1Data structure week y 5 1
Data structure week y 5 1karmuhtam
 
Data structure week y 5
Data structure week y 5Data structure week y 5
Data structure week y 5karmuhtam
 
Data structure week y 4
Data structure week y 4Data structure week y 4
Data structure week y 4karmuhtam
 
Data structure week 3
Data structure week 3Data structure week 3
Data structure week 3karmuhtam
 
Data structure week 2
Data structure week 2Data structure week 2
Data structure week 2karmuhtam
 
13. sınıfları başlık dosyaları
13.  sınıfları başlık dosyaları13.  sınıfları başlık dosyaları
13. sınıfları başlık dosyalarıkarmuhtam
 
11. stl kütüphanesi
11. stl kütüphanesi11. stl kütüphanesi
11. stl kütüphanesikarmuhtam
 
10. istisna isleme
10. istisna isleme10. istisna isleme
10. istisna islemekarmuhtam
 
9. şablonlar
9. şablonlar9. şablonlar
9. şablonlarkarmuhtam
 
8. çok biçimlilik
8. çok biçimlilik8. çok biçimlilik
8. çok biçimlilikkarmuhtam
 
7. kalıtım
7. kalıtım7. kalıtım
7. kalıtımkarmuhtam
 
6. this işaretçisi ve arkadaşlık
6. this işaretçisi ve arkadaşlık6. this işaretçisi ve arkadaşlık
6. this işaretçisi ve arkadaşlıkkarmuhtam
 
5. kurucu, yok edici ve kopyalama fonksiyonları
5. kurucu, yok edici ve kopyalama fonksiyonları5. kurucu, yok edici ve kopyalama fonksiyonları
5. kurucu, yok edici ve kopyalama fonksiyonlarıkarmuhtam
 
4. nesneler ve sınıflar
4. nesneler ve sınıflar4. nesneler ve sınıflar
4. nesneler ve sınıflarkarmuhtam
 

Mais de karmuhtam (20)

Devre analizi deney malzeme listesi
Devre analizi deney malzeme listesiDevre analizi deney malzeme listesi
Devre analizi deney malzeme listesi
 
Deney 6
Deney 6Deney 6
Deney 6
 
Deney 5
Deney 5Deney 5
Deney 5
 
Deney 3 ve 4
Deney 3 ve 4Deney 3 ve 4
Deney 3 ve 4
 
Deney 1 ve 2
Deney 1 ve 2Deney 1 ve 2
Deney 1 ve 2
 
Data structure week y 5 1
Data structure week y 5 1Data structure week y 5 1
Data structure week y 5 1
 
Data structure week y 5
Data structure week y 5Data structure week y 5
Data structure week y 5
 
Data structure week y 4
Data structure week y 4Data structure week y 4
Data structure week y 4
 
Data structure week 3
Data structure week 3Data structure week 3
Data structure week 3
 
Data structure week 2
Data structure week 2Data structure week 2
Data structure week 2
 
13. sınıfları başlık dosyaları
13.  sınıfları başlık dosyaları13.  sınıfları başlık dosyaları
13. sınıfları başlık dosyaları
 
11. stl kütüphanesi
11. stl kütüphanesi11. stl kütüphanesi
11. stl kütüphanesi
 
10. istisna isleme
10. istisna isleme10. istisna isleme
10. istisna isleme
 
9. şablonlar
9. şablonlar9. şablonlar
9. şablonlar
 
8. çok biçimlilik
8. çok biçimlilik8. çok biçimlilik
8. çok biçimlilik
 
7. kalıtım
7. kalıtım7. kalıtım
7. kalıtım
 
6. this işaretçisi ve arkadaşlık
6. this işaretçisi ve arkadaşlık6. this işaretçisi ve arkadaşlık
6. this işaretçisi ve arkadaşlık
 
5. kurucu, yok edici ve kopyalama fonksiyonları
5. kurucu, yok edici ve kopyalama fonksiyonları5. kurucu, yok edici ve kopyalama fonksiyonları
5. kurucu, yok edici ve kopyalama fonksiyonları
 
4. yapılar
4. yapılar4. yapılar
4. yapılar
 
4. nesneler ve sınıflar
4. nesneler ve sınıflar4. nesneler ve sınıflar
4. nesneler ve sınıflar
 

Último

Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajanpragatimahajan3
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingTeacherCyreneCayanan
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room servicediscovermytutordmt
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...fonyou31
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...PsychoTech Services
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 

Último (20)

Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room service
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 

Data structure week 1

  • 1. Chapter 1 Data Structures Assoc. Prof. Dr. Oğuz FINDIK 2016-2017 KBUZEM KARABUK UNIVERSITY 1
  • 2.  Referencess Books  A book on C All KELLEY, İra POHL  Data Structures and Program Design in C++ By Robert L. Kruse and Alexander J Ryba Referencess Book 2
  • 3.  You can not do anything without data on world . İf you want to proceed add operator, you should have at least two number.  Computer sciences deal with storing, organizing and retrieving effectively of data.  Computer programmer should get data from user or another sources and use them.  for this purpose you have to use data structure for every software program or system. Why data structures is important for computer engineering? 3
  • 4.  WE will use eclipse IDE for developing program in this course.  Steps to install Eclipse and run  Download eclipse Neon from http://www.eclipse.org/downloads/  Choose Eclipse IDE for C/C++ Developers and install  You should download and install MinGW GCC http://www.mingw.org/ Eclipse 4
  • 5.  Functions break large computing tasks into smaller ones.  Taking a problem and breaking into small, manageable pieces is ritical to writing large programs.  So important definition for function,  Functions return values to where is invoked. C programming 5
  • 6.  Function definition  type function_name(parameter list ) {declerations statements}  The parameter list is a comma-seperated list of declarations. Functions 6
  • 9.  return; // return ++a; // return (a*b)  When a return statement is encountered, execution of the function is terminated and control is passed back to calling environment. İf the return statement contains an expression, then the value of the expressions is passed to the calling environment as well. Return Statement 9
  • 11.  Every variable and function in C has two attributes. Type and storage class. Four storage classes are automatics, external, register and static with corresponding  auto extern register static Storage Classes 11
  • 12.  Storage class auto:  Variables declared within function are automatic by default. These variables can be used in scope of the function.  Storage class extern:  One methods of transmitting information across blocks and functions is to use external variables. When a variable is declared outside a function, storage is permanently assigned to it, and its storage class is extern. Storage Classes 12
  • 13.  #include <stdio.h>  extern int a = 1, b = 2;  c = 3;  int f(void);  int main(void) {  printf("%3dn", f());  printf("%3d%3d%3dn", a, b, c);  return 0;  }  int f(void) {  auto int b, c;  a = b = c = 4;  return (a + b + c);  } Example 13
  • 14. file2.c int f(void) { extern a; int b, c; b = c = a; return (a + b + c); } Extern keyword  This use of extern is used to tell the compiler to ‘’look for it elsewhere’’ either in this file or in some other file. Örnek1.c #include <stdio.h> int a = 1, b = 2; c = 3; int f(void); int main(void) { printf("%3dn", f()); printf("%3d%3d%3dn", a, b, c); return 0; } 14
  • 15.  Storage class register tells the compiler that the association variables should be stored in high-speed memory registers. #include <stdio.h> #include <time.h> int a =1; #define N 10000 int main(void) { clock_t start, end; double cpu_time_used; register double i; start = clock(); for(i=0;i<N;i=i+0.0001); end = clock(); cpu_time_used = ((double) (end - start)) / CLOCKS_PER_SEC; printf("Running time is %f",cpu_time_used); return 0; } Storage Class Register  Running time is 0,163 second with register variable.  Running time is 0,419 second without register variable. 15
  • 16.  Static declarations have two important and distinct uses. One of them is to allow a local variable to retain its previous value when the block is reentered. Storage class static 16
  • 17.  The second and more subtle use of static is in connection with external declarations. İt is use to restriction of the scope of the variable. Storage class static 17
  • 18.  A typical memory representation of C program consists of following sections.  1. Text segment 2. Initialized data segment 3. Uninitialized data segment 4. Stack 5. Heap 18 Memory Layout of C Programs
  • 19.  1. Text Segment:  A text segment , also known as a code segment or simply as text, is one of the sections of a program in an object file or in memory, which contains executable instructions.  Usually, the text segment is sharable so that only a single copy needs to be in memory for frequently executed programs, such as text editors, the C compiler, the shells, and so on. Also, the text segment is often read-only, to prevent a program from accidentally modifying its instructions. 19 Memory Layout of C Programs
  • 20.  2. Initialized Data Segment: A data segment is a portion of virtual address space of a program, which contains the global variables and static variables that are initialized by the programmer.  3. Uninitialized Data Segment:Data in this segment is initialized by the kernel to arithmetic 0 before the program starts executing uninitialized data starts at the end of the data segment and contains all global variables and static variables that are initialized to zero or do not have explicit initialization in source code. 20 Memory Layout of C Programs
  • 21.  4. Stack:  Stack, where automatic variables are stored, along with information that is saved each time a function is called. Each time a function is called, the address of where to return to and certain information about the caller’s environment, such as some of the machine registers, are saved on the stack. The newly called function then allocates room on the stack for its automatic and temporary variables.  This is how recursive functions in C can work. Each time a recursive function calls itself, a new stack frame is used, so one set of variables doesn’t interfere with the variables from another instance of the function. 21 Memory Layout of C Programs
  • 22.  5. Heap:  Heap is the segment where dynamic memory allocation usually takes place.  Heap area is managed by malloc, realloc, and free. 22 Memory Layout of C Programs
  • 23. #include <stdio.h> int global; /* Uninitialized variable stored in bss*/ int main(void) { int *ptr_one; ptr_one = (int *)malloc(sizeof(int)); int c;//stack static int i = 100; /* Initialized static variable stored in DS*/ return 0; } 23 Example
  • 24.  A function is said to be recursive if it class itself directly or indirectly. in C, all functions can be used recursively, including main function. Recursion 24
  • 26.  Typically, a large program is written in a separate directory as a collection of .h and .c file, with each .c file contains one or more functions definition  When preprocessor encounters #include "pgm.h« directive search this file in the same directory or system-dependent places. İf it cannot be found, preprocessor issues an error message and compilations stops. Developing Large Program 26
  • 27.  .h files contain #includes, #defines, templates of enumaration types, templates of structure and union types, and list of function prototype at the bottom.  pgm.h file:  #include <stdio.h>  #include <stdlib.h>  #define N 3  void fct1(int k);  void fct2(void);  void wrt_info(char *); Developing Large Program 27
  • 28.  fct.c file  #include "pgm.h"  void fct1(int n)  {  int i;  printf("Hello from fct1()n");  for(i=0;i<n;++i)  fct2();  }  void fct2(void){  printf("Hello from fct2()n");  } Example 28
  • 29.  wrt.c file:  #include "pgm.h"  void wrt_info(char *pgm_name){  printf("Usage: %snn",pgm_name);  printf("%sn",  "Hello from wrt_info-1n"  "Hello from wrt_info-2n"  "Hello from wrt_info-3n");  } Example  main.c file:  #include "pgm.h"  int main(void) {  char ans;  int i, n = N;  printf("%s", "This program does not do very much.n "  "Do you want to more information?");  fflush(stdout);  scanf("%c", &ans);  if (ans == 'y' || ans == 'Y')  wrt_info("pgm");  for (i = 0; i < n; ++i)  fct1(i);  printf("Bye!n");  return 0;  }  } 29
  • 30. Tower of Hanoi  Write c code that solves this problem. You have to use recursive function. 30