SlideShare a Scribd company logo
DASTURLASH 1 1
MUXAMMED AL-XOREZMIY ATÍNDAǴÍ
TASHKENT INFORMACIYALÍQ TEXNOLOGIYALARÍ UNIVERSITETI
NÓKIS FILIALÍ
PROGRAMMALASTÍRÍW II
Konteynerlerdiń adapterleri.
6
Tema
ARTIKBAYEV MAHKAM
ARTIKBAYEVICH
Programmalıq injiniring hám
matematikalıq modellestiriw
kafedrası docenti w.w.a., PhD.
DASTURLASH 2
Lekciya jobası
2
Funktorlardiń qollaniliwi.
4
Stack konteyneri.
1
Nawbet (queue). Priority_queue (ustin
nawbetler).
2
Konteynerler menen islew algoritmleri.
3
Juwmaq
5
PROGRAMMALASTÍRÍW II
DASTURLASH 2 3
Stek
Stek dep sonday strukturaǵa aytıladıki, stekka kelip
túsken aqırǵı elementke birinshi bolıp xızmet kórsetiledi
hám stekdan shiǵarıladı. Usı kórinistegi xizmet
kórsetiwdi LIFO (Last input-First output, yaǵnıy aqırǵı
kelgen - birinshi ketedi) ataw qabıl etilgen. Stek bir
tárepden ashıq boladı.
Stack = g’aram, top, bo'glam (angl.)
Maselen:
PROGRAMMALASTÍRÍW II
DASTURLASH 2 4
Stekga misal
Másele:[], {} hám () ush tiplardan shólkemlesken qatar berilgen.
Qawıslar tuwrı qoyılǵanlıǵın tekseriń (basqa simvollarga qaramagan
halda ). Mısalı :
[ () ]{} ][ [ ({) ]}
Sheshim: qawıslar ichma ichligini esaplaǵısh. Egerde esaplaǵısh 0
bolsa, qawıs to'gri qoyılǵan boladı.
Bu masalani uchta
hisoblagich menen qilsa
bo’ladimi?
? [ ( { ) ] }
(: 0 1 0
[: 0 1 0
{: 0 1 0
[ ( { ) ] }
( ( ) ) ( )
1 2 1 0 1 0
( ( ) ) ( ) ( ( ) ) ) (
1 2 1 0 -1 0
( ( ) ) ) ( ( ( ) ) (
1 2 1 0 1
( ( ) ) (
PROGRAMMALASTÍRÍW II
DASTURLASH 2 5
Dawamı…
[ ( ( ) ) ] { }
[ [
(
[
(
(
[
(
(
[
(
[ { {
Algoritm:
1) Basında stek bos ;
2) Cikl basında qatar barlıq simvollarini tártip boyıınsha kórip shıǵamız ;
3) Eger náwbettegi simvol ashılatuǵın qawıs bolsa, onı stek basına ótkeremiz;
4) Eger simvol jabılatuǵın qawıs bolsa, stek basın tekseremiz: onda berilgen
qawsırmaǵa uyqas ashılatuǵın qawıs bolıwı kerek (egerde bunday bolmasa, ol
halda qátelik);
5) Eger stek aqırı bos bolmasa, ol halda ańlatpa nadurıs.
{
PROGRAMMALASTÍRÍW II
DASTURLASH 2 6
Stekni ámelge asırıw (massiv)
Struktura-stek:
const MAXSIZE = 100;
struct Stack {
char data[MAXSIZE]; // 100 ta simvolli stek
int size; // elementlar soni
};
Element qosiw:
int Push ( Stack &S, char x )
{
if ( S.size == MAXSIZE ) return 0;
S.data[S.size] = x;
S.size ++;
return 1;
}
Qátelik: stekni
toltırıw
Element qosıw
Qátelik joq
PROGRAMMALASTÍRÍW II
DASTURLASH 2 7
Stekni ámelge asırıw (massiv)
char Pop ( Stack &S )
{
if ( S.size == 0 ) return char(255);
S.size --;
return S.data[S.size];
}
Basınan elementti óshiriw:
Bospa yamasa yaq?
int isEmpty ( Stack &S )
{
if ( S.size == 0 )
return 1;
else return 0;
}
Qátelik:
stek bos
int isEmpty ( Stack &S )
{
return (S.size == 0);
}
PROGRAMMALASTÍRÍW II
DASTURLASH 2 8
PROGRAMMALASTÍRÍW II
DASTURLASH 2 9
Stek
Universal stek hár bir túyini informaciya
bólegi void túrindegi kórsetkishten ibarat
struktura bolıp tabıladı
struct slist_node
{
void* info;
struct slist_node* pred;
};
Stek túyini dizim túyininen parqı sonda,
ózinden aldınǵı túyin adresin saqlawshı
kórsetkish isletilgen.
PROGRAMMALASTÍRÍW II
DASTURLASH 2 10
Stek
Stek ózi bólek struktura retinde kiritilgen
struct stack
{
struct slist_node* end;
int size;
int width;
};
Stackda end aqırǵı túyinge kórsetkish, width
maǵlıwmat kólemi, size náwbettegi
elementler sanı.
PROGRAMMALASTÍRÍW II
DASTURLASH 2 11
Stek (tiykarǵı funksiyalar )
Void pop (struct stack*p) - stek aqırındaǵı elementti
óshiriw.
void push (struct stack*p, void* val) -stek aqırına
element qosıw. Bul jerde val kiritilip atırǵan maǵlıwmatqa
kórsetkish.
char* tap (struct stack p) - stek aqırındaǵı túyin
informaciya bólegine kórsetkish qaytarıw.
int empty (struct stack p) - stek boslıǵın tekseriw.
int size (struct stack p) - stek elementleri sanı.
Bunnan tısqarı stekni inisiallash ushın tómendegi bas
betlı funksiya kiritilgen
void ini_stack (struct stack* p, int n) - n kiritilip atırǵan
maǵlıwmatlar kólemi.
PROGRAMMALASTÍRÍW II
DASTURLASH 2 12
Nawbet
Biz nawbet penen kóp orınlarda dus kelamiz:
magazinda, oqılıwında, ishda hám taǵı basqa. Ádetde
biz oǵan itibar bermeymiz. Programmalıq sistemalarda
da bul nawbet túsinigi isletiledi.
Mısalı, hújjetti baspadan shıǵarıw ushın printerge
jo'natsak, ol nawbetke turadı.
Nawbet bizge ne ushın kerek!
!
Alabatta nawbet 1-orında tártip ornatıw ushın zárúr.
Nawbet qanday isleydi!
!
PROGRAMMALASTÍRÍW II
DASTURLASH 2 13
Nawbet
1
2
3
4
5
6
nawbet - sızıqlı maǵlıwmatlar strukturası bolıp, elementti tek
nawbet aqırınan kirgiziw (nawbet aqırı ), elementti óshiriw bolsa tek
nawbet basqa aqırınan ámelge asıriladı (nawbet bası ).
FIFO = First Ín - First Out
«Birinshi kelgen, birinshi ketedi».
nawbet ústinde ámeller:
1. nawbet aqırınan element qosıw (PushTail = aqırınan kirgiziw);
2. nawbet basınan elementti óshiriw (Pop).
PROGRAMMALASTÍRÍW II
DASTURLASH 2 14
nawbetti ámelge asırıw (dızbek)
1
1 2
1 2 3
1 2 3
Eń ápiwayı usıl
1) Aldınan massivti belgilew;
2) Náwbetten tańlawda barlıq elementlerdi jıljıtıw kerek.
PROGRAMMALASTÍRÍW II
DASTURLASH 2 15
nawbetti ámelge asırıw (sheńberli massiv)
1 2
Head Tail
1 2 3
2 3 2 3 4
3 4
Bunday náwbette neshe
element saqlaw
múmkin?
?
«navbat bos» hám
«navbat tolıq» qanday
parıqlaw múmkin?
?
3 4
5
PROGRAMMALASTÍRÍW II
DASTURLASH 2 16
Nawbetti ámelge asırıw (sheńberli massiv)
const MAXSIZE = 100;
struct Queue {
int data[MAXSIZE];
int head, tail;
};
Maǵlıwmatlar strukturası :
nawbetke qosıw :
int PushTail ( Queue &Q, int x )
{
if ( Q.head == (Q.tail+2) % MAXSIZE )
return 0;
Q.tail = (Q.tail + 1) % MAXSIZE;
Q.data[Q.tail] = x;
return 1;
}
Sheńberdi
jasırıw
% MAXSIZE
Nawbet
tolıq, qosıp
bolmaydı
Tabıslı qosıldı
PROGRAMMALASTÍRÍW II
DASTURLASH 2 17
Nawbetti ámelge asırıw (sheńberli massiv)
Nawbetten tańlaw :
int Pop ( Queue &Q )
{
int temp;
if ( Q.head == (Q.tail + 1) % MAXSIZE )
return 32767;
temp = Q.data[Q.head];
Q.head = (Q.head + 1) % MAXSIZE;
return temp;
}
Nawbet bos
Birinshi elementti
alıw
Onı náwbetten
óshiriw
PROGRAMMALASTÍRÍW II
DASTURLASH 2 18
Ústin turatuǵın nawbet (Priority_queue)
Biz hámmemiz “Metan”da náwbette turǵanmız. Gezekti
hár túrlı túrleri bar. Mısalı, prioritet boyınsha gezek.
Turmıstan mısal : veteranlar hám mayıplar gezeksiz
ótkeriledi (olardı prioriteti joqarı ).
Klassik gezekti kórip shıǵamız :
birinshi kelgen birinshi ketedi (FIFO - first input, first output)
Gezek hár eki tárepden ashıq boladı.
PROGRAMMALASTÍRÍW II
DASTURLASH 2 19
Ústin turatuǵın nawbet (Priority_queue)
Universal gezek hár bir túyini informaciya bólegi void
túrindegi kórsetkishten ibarat struktura bolıp tabıladı:
Bul jerde beg birinshi túyinge
kórsetkish, end aqırǵı
túyinge kórsetkish, width
maǵlıwmat kólemi, size
náwbettegi elementler sanı
struct slist_node
{
void* info;
struct slist_node* next;
}; struct que
{
struct slist_node* beg;
struct slist_node* end;
int size;
int width;
};
PROGRAMMALASTÍRÍW II
DASTURLASH 2 20
Ústin turatuǵın Gezek (tiykarǵı funksiyalar )
void pop(struct que*p) – Gezek aqırındaǵı elementti
óshiriw.
void push(struct que*p, void* val) –Gezek basına
element qosıw. Bul jerde val kiritilip atırǵan
maǵlıwmatqa kórsetkish.
char* top(struct que p) – Gezek bası daǵı túyin
informaciya bólegine kórsetkish qaytarıw .
int empty(struct que p) – Gezek boslıǵın tekseriw.
int size (struct que p) – Gezek elementleri sanı.
Bunnan tısqarı gezekti inisiallash ushın tómendegi bas
betlı funksiya kiritilgen.
void ini_que(struct que* p,int n) – Bul jerde n kiritilip
atırǵan maǵlıwmatlar kólemi.
PROGRAMMALASTÍRÍW II
DASTURLASH 2 21
DEK(deque)
Dek(deque = double ended queue, eki tarepleme
gezek) – Bul da sızıqlı struktura bolıp ol jaǵdayda jańa
elementti eki tárepinen qosıw múmkin.
1
2 3
4 5
6
Dek ústinde ámeller :
1)Basınan element qosıw (Push);
2) Basınan element óshiriw (Pop);
3) Aqırınan element qosıw (PushTail);
4) Aqırınan element óshiriw (PopTail).
PROGRAMMALASTÍRÍW II
DASTURLASH 2 22
Funktorlar
• Funktorlar - Bul funksiyalar sıyaqlı shaqırıq qılıw (shaqırıw )
múmkin bolǵan qálegen tipdagi obiektler bolıp tabıladı.
Yaǵnıy () ámeli qayta júklengen obiektler bolıp tabıladı.
PROGRAMMALASTÍRÍW II
DASTURLASH 2 23
1. Funktorlarga tiyisli programma
PROGRAMMALASTÍRÍW II
DASTURLASH 2 24
Dawamı…
PROGRAMMALASTÍRÍW II
DASTURLASH 2 25
2. Funktorlarga tiyisli programma
PROGRAMMALASTÍRÍW II
DASTURLASH 2 26
Dawamı…
PROGRAMMALASTÍRÍW II
DASTURLASH 2
Juwmaq
27
Juwmaq ornında sonı aytıp ótiw kerek, konteynerli
adapterlerdiń yad tárepinen shegaralanbaǵanlıǵı hám de
bul konteynerlarga maǵlıwmat qosıw hám óshiriw
qolaylıǵı bar.
Búgingi sabaǵımızda :
✓ Stack konteyneri
✓ Gezek
✓ Ústin turatuǵın Gezek (Priority_queue)
✓ DEK (deque)
konteynerleri menen tanıstıq.
PROGRAMMALASTÍRÍW II
DASTURLASH 1 28
MUXAMMED AL-XOREZMIY ATÍNDAǴÍ
TASHKENT INFORMACIYALÍQ TEXNOLOGIYALARÍ UNIVERSITETI
NÓKIS FILIALÍ
ITIBARIŃIZ
USHÍN
RAXMET!
ARTIKBAYEV MAHKAM
ARTIKBAYEVICH
Programmalıq injiniring hám
matematikalıq modellestiriw
kafedrası docenti w.w.a., PhD.

More Related Content

Featured

AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
marketingartwork
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
Skeleton Technologies
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
SpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Lily Ray
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
Rajiv Jayarajah, MAppComm, ACC
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
Christy Abraham Joy
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
Vit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
MindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
RachelPearson36
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Applitools
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
GetSmarter
 
ChatGPT webinar slides
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slides
Alireza Esmikhani
 
More than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike RoutesMore than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike Routes
Project for Public Spaces & National Center for Biking and Walking
 

Featured (20)

AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 
ChatGPT webinar slides
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slides
 
More than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike RoutesMore than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike Routes
 

6 Lekciya_Prog II.pdf

  • 1. DASTURLASH 1 1 MUXAMMED AL-XOREZMIY ATÍNDAǴÍ TASHKENT INFORMACIYALÍQ TEXNOLOGIYALARÍ UNIVERSITETI NÓKIS FILIALÍ PROGRAMMALASTÍRÍW II Konteynerlerdiń adapterleri. 6 Tema ARTIKBAYEV MAHKAM ARTIKBAYEVICH Programmalıq injiniring hám matematikalıq modellestiriw kafedrası docenti w.w.a., PhD.
  • 2. DASTURLASH 2 Lekciya jobası 2 Funktorlardiń qollaniliwi. 4 Stack konteyneri. 1 Nawbet (queue). Priority_queue (ustin nawbetler). 2 Konteynerler menen islew algoritmleri. 3 Juwmaq 5 PROGRAMMALASTÍRÍW II
  • 3. DASTURLASH 2 3 Stek Stek dep sonday strukturaǵa aytıladıki, stekka kelip túsken aqırǵı elementke birinshi bolıp xızmet kórsetiledi hám stekdan shiǵarıladı. Usı kórinistegi xizmet kórsetiwdi LIFO (Last input-First output, yaǵnıy aqırǵı kelgen - birinshi ketedi) ataw qabıl etilgen. Stek bir tárepden ashıq boladı. Stack = g’aram, top, bo'glam (angl.) Maselen: PROGRAMMALASTÍRÍW II
  • 4. DASTURLASH 2 4 Stekga misal Másele:[], {} hám () ush tiplardan shólkemlesken qatar berilgen. Qawıslar tuwrı qoyılǵanlıǵın tekseriń (basqa simvollarga qaramagan halda ). Mısalı : [ () ]{} ][ [ ({) ]} Sheshim: qawıslar ichma ichligini esaplaǵısh. Egerde esaplaǵısh 0 bolsa, qawıs to'gri qoyılǵan boladı. Bu masalani uchta hisoblagich menen qilsa bo’ladimi? ? [ ( { ) ] } (: 0 1 0 [: 0 1 0 {: 0 1 0 [ ( { ) ] } ( ( ) ) ( ) 1 2 1 0 1 0 ( ( ) ) ( ) ( ( ) ) ) ( 1 2 1 0 -1 0 ( ( ) ) ) ( ( ( ) ) ( 1 2 1 0 1 ( ( ) ) ( PROGRAMMALASTÍRÍW II
  • 5. DASTURLASH 2 5 Dawamı… [ ( ( ) ) ] { } [ [ ( [ ( ( [ ( ( [ ( [ { { Algoritm: 1) Basında stek bos ; 2) Cikl basında qatar barlıq simvollarini tártip boyıınsha kórip shıǵamız ; 3) Eger náwbettegi simvol ashılatuǵın qawıs bolsa, onı stek basına ótkeremiz; 4) Eger simvol jabılatuǵın qawıs bolsa, stek basın tekseremiz: onda berilgen qawsırmaǵa uyqas ashılatuǵın qawıs bolıwı kerek (egerde bunday bolmasa, ol halda qátelik); 5) Eger stek aqırı bos bolmasa, ol halda ańlatpa nadurıs. { PROGRAMMALASTÍRÍW II
  • 6. DASTURLASH 2 6 Stekni ámelge asırıw (massiv) Struktura-stek: const MAXSIZE = 100; struct Stack { char data[MAXSIZE]; // 100 ta simvolli stek int size; // elementlar soni }; Element qosiw: int Push ( Stack &S, char x ) { if ( S.size == MAXSIZE ) return 0; S.data[S.size] = x; S.size ++; return 1; } Qátelik: stekni toltırıw Element qosıw Qátelik joq PROGRAMMALASTÍRÍW II
  • 7. DASTURLASH 2 7 Stekni ámelge asırıw (massiv) char Pop ( Stack &S ) { if ( S.size == 0 ) return char(255); S.size --; return S.data[S.size]; } Basınan elementti óshiriw: Bospa yamasa yaq? int isEmpty ( Stack &S ) { if ( S.size == 0 ) return 1; else return 0; } Qátelik: stek bos int isEmpty ( Stack &S ) { return (S.size == 0); } PROGRAMMALASTÍRÍW II
  • 9. DASTURLASH 2 9 Stek Universal stek hár bir túyini informaciya bólegi void túrindegi kórsetkishten ibarat struktura bolıp tabıladı struct slist_node { void* info; struct slist_node* pred; }; Stek túyini dizim túyininen parqı sonda, ózinden aldınǵı túyin adresin saqlawshı kórsetkish isletilgen. PROGRAMMALASTÍRÍW II
  • 10. DASTURLASH 2 10 Stek Stek ózi bólek struktura retinde kiritilgen struct stack { struct slist_node* end; int size; int width; }; Stackda end aqırǵı túyinge kórsetkish, width maǵlıwmat kólemi, size náwbettegi elementler sanı. PROGRAMMALASTÍRÍW II
  • 11. DASTURLASH 2 11 Stek (tiykarǵı funksiyalar ) Void pop (struct stack*p) - stek aqırındaǵı elementti óshiriw. void push (struct stack*p, void* val) -stek aqırına element qosıw. Bul jerde val kiritilip atırǵan maǵlıwmatqa kórsetkish. char* tap (struct stack p) - stek aqırındaǵı túyin informaciya bólegine kórsetkish qaytarıw. int empty (struct stack p) - stek boslıǵın tekseriw. int size (struct stack p) - stek elementleri sanı. Bunnan tısqarı stekni inisiallash ushın tómendegi bas betlı funksiya kiritilgen void ini_stack (struct stack* p, int n) - n kiritilip atırǵan maǵlıwmatlar kólemi. PROGRAMMALASTÍRÍW II
  • 12. DASTURLASH 2 12 Nawbet Biz nawbet penen kóp orınlarda dus kelamiz: magazinda, oqılıwında, ishda hám taǵı basqa. Ádetde biz oǵan itibar bermeymiz. Programmalıq sistemalarda da bul nawbet túsinigi isletiledi. Mısalı, hújjetti baspadan shıǵarıw ushın printerge jo'natsak, ol nawbetke turadı. Nawbet bizge ne ushın kerek! ! Alabatta nawbet 1-orında tártip ornatıw ushın zárúr. Nawbet qanday isleydi! ! PROGRAMMALASTÍRÍW II
  • 13. DASTURLASH 2 13 Nawbet 1 2 3 4 5 6 nawbet - sızıqlı maǵlıwmatlar strukturası bolıp, elementti tek nawbet aqırınan kirgiziw (nawbet aqırı ), elementti óshiriw bolsa tek nawbet basqa aqırınan ámelge asıriladı (nawbet bası ). FIFO = First Ín - First Out «Birinshi kelgen, birinshi ketedi». nawbet ústinde ámeller: 1. nawbet aqırınan element qosıw (PushTail = aqırınan kirgiziw); 2. nawbet basınan elementti óshiriw (Pop). PROGRAMMALASTÍRÍW II
  • 14. DASTURLASH 2 14 nawbetti ámelge asırıw (dızbek) 1 1 2 1 2 3 1 2 3 Eń ápiwayı usıl 1) Aldınan massivti belgilew; 2) Náwbetten tańlawda barlıq elementlerdi jıljıtıw kerek. PROGRAMMALASTÍRÍW II
  • 15. DASTURLASH 2 15 nawbetti ámelge asırıw (sheńberli massiv) 1 2 Head Tail 1 2 3 2 3 2 3 4 3 4 Bunday náwbette neshe element saqlaw múmkin? ? «navbat bos» hám «navbat tolıq» qanday parıqlaw múmkin? ? 3 4 5 PROGRAMMALASTÍRÍW II
  • 16. DASTURLASH 2 16 Nawbetti ámelge asırıw (sheńberli massiv) const MAXSIZE = 100; struct Queue { int data[MAXSIZE]; int head, tail; }; Maǵlıwmatlar strukturası : nawbetke qosıw : int PushTail ( Queue &Q, int x ) { if ( Q.head == (Q.tail+2) % MAXSIZE ) return 0; Q.tail = (Q.tail + 1) % MAXSIZE; Q.data[Q.tail] = x; return 1; } Sheńberdi jasırıw % MAXSIZE Nawbet tolıq, qosıp bolmaydı Tabıslı qosıldı PROGRAMMALASTÍRÍW II
  • 17. DASTURLASH 2 17 Nawbetti ámelge asırıw (sheńberli massiv) Nawbetten tańlaw : int Pop ( Queue &Q ) { int temp; if ( Q.head == (Q.tail + 1) % MAXSIZE ) return 32767; temp = Q.data[Q.head]; Q.head = (Q.head + 1) % MAXSIZE; return temp; } Nawbet bos Birinshi elementti alıw Onı náwbetten óshiriw PROGRAMMALASTÍRÍW II
  • 18. DASTURLASH 2 18 Ústin turatuǵın nawbet (Priority_queue) Biz hámmemiz “Metan”da náwbette turǵanmız. Gezekti hár túrlı túrleri bar. Mısalı, prioritet boyınsha gezek. Turmıstan mısal : veteranlar hám mayıplar gezeksiz ótkeriledi (olardı prioriteti joqarı ). Klassik gezekti kórip shıǵamız : birinshi kelgen birinshi ketedi (FIFO - first input, first output) Gezek hár eki tárepden ashıq boladı. PROGRAMMALASTÍRÍW II
  • 19. DASTURLASH 2 19 Ústin turatuǵın nawbet (Priority_queue) Universal gezek hár bir túyini informaciya bólegi void túrindegi kórsetkishten ibarat struktura bolıp tabıladı: Bul jerde beg birinshi túyinge kórsetkish, end aqırǵı túyinge kórsetkish, width maǵlıwmat kólemi, size náwbettegi elementler sanı struct slist_node { void* info; struct slist_node* next; }; struct que { struct slist_node* beg; struct slist_node* end; int size; int width; }; PROGRAMMALASTÍRÍW II
  • 20. DASTURLASH 2 20 Ústin turatuǵın Gezek (tiykarǵı funksiyalar ) void pop(struct que*p) – Gezek aqırındaǵı elementti óshiriw. void push(struct que*p, void* val) –Gezek basına element qosıw. Bul jerde val kiritilip atırǵan maǵlıwmatqa kórsetkish. char* top(struct que p) – Gezek bası daǵı túyin informaciya bólegine kórsetkish qaytarıw . int empty(struct que p) – Gezek boslıǵın tekseriw. int size (struct que p) – Gezek elementleri sanı. Bunnan tısqarı gezekti inisiallash ushın tómendegi bas betlı funksiya kiritilgen. void ini_que(struct que* p,int n) – Bul jerde n kiritilip atırǵan maǵlıwmatlar kólemi. PROGRAMMALASTÍRÍW II
  • 21. DASTURLASH 2 21 DEK(deque) Dek(deque = double ended queue, eki tarepleme gezek) – Bul da sızıqlı struktura bolıp ol jaǵdayda jańa elementti eki tárepinen qosıw múmkin. 1 2 3 4 5 6 Dek ústinde ámeller : 1)Basınan element qosıw (Push); 2) Basınan element óshiriw (Pop); 3) Aqırınan element qosıw (PushTail); 4) Aqırınan element óshiriw (PopTail). PROGRAMMALASTÍRÍW II
  • 22. DASTURLASH 2 22 Funktorlar • Funktorlar - Bul funksiyalar sıyaqlı shaqırıq qılıw (shaqırıw ) múmkin bolǵan qálegen tipdagi obiektler bolıp tabıladı. Yaǵnıy () ámeli qayta júklengen obiektler bolıp tabıladı. PROGRAMMALASTÍRÍW II
  • 23. DASTURLASH 2 23 1. Funktorlarga tiyisli programma PROGRAMMALASTÍRÍW II
  • 25. DASTURLASH 2 25 2. Funktorlarga tiyisli programma PROGRAMMALASTÍRÍW II
  • 27. DASTURLASH 2 Juwmaq 27 Juwmaq ornında sonı aytıp ótiw kerek, konteynerli adapterlerdiń yad tárepinen shegaralanbaǵanlıǵı hám de bul konteynerlarga maǵlıwmat qosıw hám óshiriw qolaylıǵı bar. Búgingi sabaǵımızda : ✓ Stack konteyneri ✓ Gezek ✓ Ústin turatuǵın Gezek (Priority_queue) ✓ DEK (deque) konteynerleri menen tanıstıq. PROGRAMMALASTÍRÍW II
  • 28. DASTURLASH 1 28 MUXAMMED AL-XOREZMIY ATÍNDAǴÍ TASHKENT INFORMACIYALÍQ TEXNOLOGIYALARÍ UNIVERSITETI NÓKIS FILIALÍ ITIBARIŃIZ USHÍN RAXMET! ARTIKBAYEV MAHKAM ARTIKBAYEVICH Programmalıq injiniring hám matematikalıq modellestiriw kafedrası docenti w.w.a., PhD.