SlideShare une entreprise Scribd logo
1  sur  11
KBUZEM
Karabük Üniversitesi
Uzaktan Eğitim Araştırma ve Uygulama Merkezi
Örnek 12.1
#include <conio.h>
using namespace std;
#include <iostream.h>
#include <iostream>
#include <vector>
int main()
{
vector<int> v; //create a vector of ints
v.push_back(10); //put values at end of array
v.push_back(11);
v.push_back(12);
v.push_back(13);
12. HAFTA
NESNEYE DAYALI PROGRAMLAMA
BLM301
Mikroişlemciler
2
v[0] = 20; //replace with new values
v[3] = 23;
for(int j=0; j<v.size(); j++) //display vector contents
cout << v[j] <<" " ; //20 11 12 23
cout << endl;
getch();
return 0;
}
#include <conio.h>
using namespace std;
#include <iostream.h>
#include <iostream>
#include <vector>
// demonstrates constructors, swap(), empty(), back(), pop_back()
using namespace std;
int main()
{ //an array of doubles
int arr[] = { 23, 12, 113, 40 };
vector<int> v1(arr, arr+3); //initialize vector to array
vector<int> v2(3); //empty vector of size 4
v1.swap(v2); //swap contents of v1 and v2
while( !v2.empty() ) //until vector is empty,
{
cout << v2.back() << " "; //display the last element
v2.pop_back(); //remove the last element
}
cout << endl;
getch();
return 0;
}
Örnek 12.3
#include <conio.h>
using namespace std;
#include <iostream.h>
#include <iostream>
#include <vector>
int main()
{
int arr[] = { 100, 110, 120, 130 }; //an array of ints
Karabük Üniversitesi Uzaktan Eğitim Araştırma ve Uygulama Merkezi
Mühendislik Fakültesi No: 215 Balıklarkayası Mevkii 78050 Karabük TÜRKİYE
BLM301
Mikroişlemciler
3
vector<int> v(arr, arr+4); //initialize vector to array
cout <<"nBefore insertion:";
for(int j=0; j<v.size(); j++) //display all elements
cout << v[j] <<" ";
v.insert( v.begin()+2, 115); //insert 115 at element 2
cout <<"nAfter insertion:";
for(int j=0; j<v.size(); j++) //display all elements
cout << v[j] <<" ";
v.erase( v.begin()+2 ); //erase element 2
cout << "nAfter erasure:";
for(int j=0; j<v.size(); j++) //display all elements
cout << v[j] << " ";
cout << endl;
getch();
return 0;
}
Örnek 12.4
#include <conio.h>
using namespace std;
#include <iostream.h>
#include <iostream>
//demonstrates push_front(), front(), pop_front()
#include <list>
int main()
{
list<int> ilist;
ilist.push_back(30); //push items on back
ilist.push_back(40);
ilist.push_front(20); //push items on front
ilist.push_front(10);
int size = ilist.size(); //number of items
for(int j=0; j<size; j++)
{
cout << ilist.front() <<" "; //read item from front
ilist.pop_front(); //pop item off front
}
cout << endl;
getch();
Karabük Üniversitesi Uzaktan Eğitim Araştırma ve Uygulama Merkezi
Mühendislik Fakültesi No: 215 Balıklarkayası Mevkii 78050 Karabük TÜRKİYE
BLM301
Mikroişlemciler
4
return 0;}
#include <conio.h>
using namespace std;
#include <iostream.h>
#include <iostream>
//demonstrates push_front(), front(), pop_front()
#include <list>
int main()
{
int j;
list<int> list1, list2;
int arr1[] = { 40, 30, 20, 10 };
int arr2[] = { 15, 20, 25, 30, 35 };
for(j=0; j<4; j++)
list1.push_back( arr1[j] ); //list1: 40, 30, 20, 10
for(j=0; j<5; j++)
list2.push_back( arr2[j] ); //list2: 15, 20, 25, 30, 35
list1.reverse(); //reverse list1: 10 20 30 40
list1.merge(list2); //merge list2 into list1
list1.unique(); //remove duplicate 20 and 30
int size = list1.size();
while( !list1.empty() )
{
cout << list1.front() << " "; //read item from front
list1.pop_front(); //pop item off front
}
cout << endl;
getch();
return 0;
}
Örnek 12.6
#include <conio.h>
using namespace std;
#include <iostream.h>
#include <iostream>
#include <deque>
Karabük Üniversitesi Uzaktan Eğitim Araştırma ve Uygulama Merkezi
Mühendislik Fakültesi No: 215 Balıklarkayası Mevkii 78050 Karabük TÜRKİYE
BLM301
Mikroişlemciler
5
int main()
{
deque<int> deq;
deq.push_back(30); //push items on back
deq.push_back(40);
deq.push_back(50);
deq.push_front(20); //push items on front
deq.push_front(10);
deq[2] = 33; //change middle item
for(int j=0; j<deq.size(); j++)
cout << deq[j] << " "; //display items
getch();
return 0;
}
Örnek 12.7
#include <conio.h>
#include <iostream.h>
#include <iostream>
using namespace std;
#include <vector>
int main ()
{
vector<int> v;
for (int i=1; i<=15; i++)
{
v.push_back(i);
}
cout << "myvector contains:";
vector<int>::iterator it;
for (it = v.begin() ; it != v.end(); ++it)
cout << ' ' << *it;
cout << 'n';
getch();
return 0;
}
Örnek 12.8
#include <conio.h>
#include <iostream.h>
Karabük Üniversitesi Uzaktan Eğitim Araştırma ve Uygulama Merkezi
Mühendislik Fakültesi No: 215 Balıklarkayası Mevkii 78050 Karabük TÜRKİYE
BLM301
Mikroişlemciler
6
#include <iostream>
using namespace std;
#include <vector>
#include <list>
int main()
{
int arr[] = { 2, 4, 6, 8 };
list<int> theList;
for(int k=0; k<4; k++) //fill list with array elements
{ theList.push_back( arr[k] ); }
list<int>::iterator iter; //iterator to list-of-ints
for(iter = theList.begin(); iter != theList.end(); iter++)
{ cout << *iter << " "; } //display the list
cout << endl;
iter = theList.begin();
while( iter != theList.end() )
{cout << *iter++ << " ";}
getch();
return 0;
}
Örnek 12.9
#include <conio.h>
using namespace std;
#include <iostream.h>
#include <iostream>
#include <list>
#include <vector>
int main ()
{
list<int> mylist;
list<int>::iterator it;
// set some initial values:
for (int i=1; i<=5; ++i) mylist.push_back(i); // 1 2 3 4 5
it = mylist.begin();
Karabük Üniversitesi Uzaktan Eğitim Araştırma ve Uygulama Merkezi
Mühendislik Fakültesi No: 215 Balıklarkayası Mevkii 78050 Karabük TÜRKİYE
BLM301
Mikroişlemciler
7
++it;
mylist.insert (it,10); // 1 10 2 3 4 5
for (it=mylist.begin(); it!=mylist.end(); ++it) { cout << ' ' << *it; }
getch();
return 0;
}
struct agac {
int kod;
int mal;
};
struct Acc {
list<agac*>agaclistesi;
list<Acc*>acclist;
};
Acc * acc = new Acc();
Acc * acc1 = new Acc();
Acc * acc2 = new Acc();
int al(Acc* t)
{
t->agaclistesi.pop_back();
cout<<t->agaclistesi.size()<<endl; //4 //6
return 0;
}
int main ()
{
agac * cam = new agac();
agac * kavak = new agac();
cam->kod=2;
cam->mal=5;
kavak->kod=9;
kavak->mal=25;
Karabük Üniversitesi Uzaktan Eğitim Araştırma ve Uygulama Merkezi
Mühendislik Fakültesi No: 215 Balıklarkayası Mevkii 78050 Karabük TÜRKİYE
BLM301
Mikroişlemciler
8
acc->agaclistesi.push_back(cam);
acc->agaclistesi.push_back(kavak);
acc->agaclistesi.push_back(cam);
acc->agaclistesi.push_back(kavak);
acc1->acclist.push_back(acc);
acc1->acclist.push_back(acc);
cout<<acc1->acclist.size()<<endl; //1
cout<< (acc1->acclist.front())->agaclistesi.size()<<endl; //2
acc2=acc1->acclist.front();
cout<<acc2->agaclistesi.size()<<endl;//3
al(acc1->acclist.front());//4
cout<<acc->agaclistesi.size()<<endl;//5
al(acc);//6
cout<<"son"<<endl; //7
getch();
return 0;
}
#include <conio.h>
#include <iostream>
#include <list>
using namespace std;
struct Acc {
int id;
int hop;
Karabük Üniversitesi Uzaktan Eğitim Araştırma ve Uygulama Merkezi
Mühendislik Fakültesi No: 215 Balıklarkayası Mevkii 78050 Karabük TÜRKİYE
BLM301
Mikroişlemciler
9
list<Acc*>acclist;
int al(Acc* a)
{
a->acclist.pop_back();
cout<<a->acclist.size()<<endl;
return 0;
}
};
int main ()
{
Acc * acc1 = new Acc();
Acc * acc2 = new Acc();
Acc * acc3 = new Acc();
acc1->id=1;
acc1->hop=1;
acc2->id=2;
acc2->hop=1;
acc3->id=3;
acc3->hop=1;
acc1->acclist.push_back(acc1);
acc1->acclist.push_front(acc2);
acc1->acclist.push_back(acc3);
cout<<acc1->acclist.size()<<endl; //1
acc1->al(acc1);
cout<< (acc1->acclist.front())->id<<endl; //2
getch();
return 0;
Karabük Üniversitesi Uzaktan Eğitim Araştırma ve Uygulama Merkezi
Mühendislik Fakültesi No: 215 Balıklarkayası Mevkii 78050 Karabük TÜRKİYE
BLM301
Mikroişlemciler
10
}
#include <conio.h>
#include <iostream>
#include <list>
using namespace std;
struct Acc {
int id;
int hop;
list<Acc*>acclist;
int al(Acc* a)
{
a->acclist.pop_back();
cout<<a->acclist.size()<<endl;
return 0;
}
};
int main ()
{
Acc * acc1 = new Acc();
Acc * acc2 = new Acc();
Acc * acc3 = new Acc();
acc1->id=1;
acc1->hop=1;
acc2->id=2;
acc2->hop=2;
acc3->id=3;
acc3->hop=3;
acc1->acclist.push_back(acc1);
Karabük Üniversitesi Uzaktan Eğitim Araştırma ve Uygulama Merkezi
Mühendislik Fakültesi No: 215 Balıklarkayası Mevkii 78050 Karabük TÜRKİYE
BLM301
Mikroişlemciler
11
acc1->acclist.push_front(acc2);
acc1->acclist.push_back(acc3);
cout<<acc1->acclist.size()<<endl;
list<Acc*>::iterator iter;
iter = acc1->acclist.begin();
while( iter !=acc1->acclist.end() )
{
cout << acc1->acclist.front()->id <<endl;
cout << acc1->acclist.front()->hop <<endl;
*iter++;
acc1->acclist.pop_front();
}
getch();
return 0;
}
Karabük Üniversitesi Uzaktan Eğitim Araştırma ve Uygulama Merkezi
Mühendislik Fakültesi No: 215 Balıklarkayası Mevkii 78050 Karabük TÜRKİYE

Contenu connexe

Tendances

重構—改善既有程式的設計(chapter 9)
重構—改善既有程式的設計(chapter 9)重構—改善既有程式的設計(chapter 9)
重構—改善既有程式的設計(chapter 9)
Chris Huang
 
Lec 45.46- virtual.functions
Lec 45.46- virtual.functionsLec 45.46- virtual.functions
Lec 45.46- virtual.functions
Princess Sam
 
重構—改善既有程式的設計(chapter 8)part 2
重構—改善既有程式的設計(chapter 8)part 2重構—改善既有程式的設計(chapter 8)part 2
重構—改善既有程式的設計(chapter 8)part 2
Chris Huang
 
重構—改善既有程式的設計(chapter 8)part 1
重構—改善既有程式的設計(chapter 8)part 1重構—改善既有程式的設計(chapter 8)part 1
重構—改善既有程式的設計(chapter 8)part 1
Chris Huang
 

Tendances (20)

重構—改善既有程式的設計(chapter 9)
重構—改善既有程式的設計(chapter 9)重構—改善既有程式的設計(chapter 9)
重構—改善既有程式的設計(chapter 9)
 
Introduction to julia
Introduction to juliaIntroduction to julia
Introduction to julia
 
C++ Programs
C++ ProgramsC++ Programs
C++ Programs
 
Java_practical_handbook
Java_practical_handbookJava_practical_handbook
Java_practical_handbook
 
Php unit the-mostunknownparts
Php unit the-mostunknownpartsPhp unit the-mostunknownparts
Php unit the-mostunknownparts
 
data Structure Lecture 1
data Structure Lecture 1data Structure Lecture 1
data Structure Lecture 1
 
Pro typescript.ch03.Object Orientation in TypeScript
Pro typescript.ch03.Object Orientation in TypeScriptPro typescript.ch03.Object Orientation in TypeScript
Pro typescript.ch03.Object Orientation in TypeScript
 
Node.js System: The Landing
Node.js System: The LandingNode.js System: The Landing
Node.js System: The Landing
 
Fantastic DSL in Python
Fantastic DSL in PythonFantastic DSL in Python
Fantastic DSL in Python
 
Talk - Query monad
Talk - Query monad Talk - Query monad
Talk - Query monad
 
Lec 45.46- virtual.functions
Lec 45.46- virtual.functionsLec 45.46- virtual.functions
Lec 45.46- virtual.functions
 
Metaprogramming in julia
Metaprogramming in juliaMetaprogramming in julia
Metaprogramming in julia
 
重構—改善既有程式的設計(chapter 8)part 2
重構—改善既有程式的設計(chapter 8)part 2重構—改善既有程式的設計(chapter 8)part 2
重構—改善既有程式的設計(chapter 8)part 2
 
重構—改善既有程式的設計(chapter 8)part 1
重構—改善既有程式的設計(chapter 8)part 1重構—改善既有程式的設計(chapter 8)part 1
重構—改善既有程式的設計(chapter 8)part 1
 
Being functional in PHP (PHPDay Italy 2016)
Being functional in PHP (PHPDay Italy 2016)Being functional in PHP (PHPDay Italy 2016)
Being functional in PHP (PHPDay Italy 2016)
 
classes & objects in cpp overview
classes & objects in cpp overviewclasses & objects in cpp overview
classes & objects in cpp overview
 
PhpUnit - The most unknown Parts
PhpUnit - The most unknown PartsPhpUnit - The most unknown Parts
PhpUnit - The most unknown Parts
 
DRYing to Monad in Java8
DRYing to Monad in Java8DRYing to Monad in Java8
DRYing to Monad in Java8
 
Functions
FunctionsFunctions
Functions
 
Silicon Valley JUG: JVM Mechanics
Silicon Valley JUG: JVM MechanicsSilicon Valley JUG: JVM Mechanics
Silicon Valley JUG: JVM Mechanics
 

Similaire à 12. stl örnekler

Tugas praktikukm pemrograman c++
Tugas praktikukm  pemrograman c++Tugas praktikukm  pemrograman c++
Tugas praktikukm pemrograman c++
Dendi Riadi
 
Assignement of programming & problem solving u.s ass.(1)
Assignement of programming & problem solving u.s ass.(1)Assignement of programming & problem solving u.s ass.(1)
Assignement of programming & problem solving u.s ass.(1)
Syed Umair
 
Part APurposeThis laboratory provides some experience work.docx
Part APurposeThis laboratory provides some experience work.docxPart APurposeThis laboratory provides some experience work.docx
Part APurposeThis laboratory provides some experience work.docx
dewhirstichabod
 
1- The design of a singly-linked list below is a picture of the functi (1).pdf
1- The design of a singly-linked list below is a picture of the functi (1).pdf1- The design of a singly-linked list below is a picture of the functi (1).pdf
1- The design of a singly-linked list below is a picture of the functi (1).pdf
afgt2012
 

Similaire à 12. stl örnekler (20)

C++ practical
C++ practicalC++ practical
C++ practical
 
Oops lab manual2
Oops lab manual2Oops lab manual2
Oops lab manual2
 
Tugas praktikukm pemrograman c++
Tugas praktikukm  pemrograman c++Tugas praktikukm  pemrograman c++
Tugas praktikukm pemrograman c++
 
React redux
React reduxReact redux
React redux
 
Advance java
Advance javaAdvance java
Advance java
 
Dsprograms(2nd cse)
Dsprograms(2nd cse)Dsprograms(2nd cse)
Dsprograms(2nd cse)
 
Pads lab manual final
Pads lab manual finalPads lab manual final
Pads lab manual final
 
14922 java script built (1)
14922 java script built (1)14922 java script built (1)
14922 java script built (1)
 
C++ programs
C++ programsC++ programs
C++ programs
 
Assignement of programming & problem solving u.s ass.(1)
Assignement of programming & problem solving u.s ass.(1)Assignement of programming & problem solving u.s ass.(1)
Assignement of programming & problem solving u.s ass.(1)
 
Part APurposeThis laboratory provides some experience work.docx
Part APurposeThis laboratory provides some experience work.docxPart APurposeThis laboratory provides some experience work.docx
Part APurposeThis laboratory provides some experience work.docx
 
C++ file
C++ fileC++ file
C++ file
 
C++ file
C++ fileC++ file
C++ file
 
Oop lab report
Oop lab reportOop lab report
Oop lab report
 
1- The design of a singly-linked list below is a picture of the functi (1).pdf
1- The design of a singly-linked list below is a picture of the functi (1).pdf1- The design of a singly-linked list below is a picture of the functi (1).pdf
1- The design of a singly-linked list below is a picture of the functi (1).pdf
 
CppTutorial.ppt
CppTutorial.pptCppTutorial.ppt
CppTutorial.ppt
 
Cpp tutorial
Cpp tutorialCpp tutorial
Cpp tutorial
 
Lecture#8 introduction to array with examples c++
Lecture#8 introduction to array with examples c++Lecture#8 introduction to array with examples c++
Lecture#8 introduction to array with examples c++
 
ios,objective tutorial
ios,objective tutorial ios,objective tutorial
ios,objective tutorial
 
Codes on structures
Codes on structuresCodes on structures
Codes on structures
 

Plus de karmuhtam

Plus 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
 
Data structure week 1
Data structure week 1Data structure week 1
Data structure week 1
 
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
 

Dernier

1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
QucHHunhnh
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
AnaAcapella
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 

Dernier (20)

Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptx
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 

12. stl örnekler

  • 1. KBUZEM Karabük Üniversitesi Uzaktan Eğitim Araştırma ve Uygulama Merkezi Örnek 12.1 #include <conio.h> using namespace std; #include <iostream.h> #include <iostream> #include <vector> int main() { vector<int> v; //create a vector of ints v.push_back(10); //put values at end of array v.push_back(11); v.push_back(12); v.push_back(13); 12. HAFTA NESNEYE DAYALI PROGRAMLAMA
  • 2. BLM301 Mikroişlemciler 2 v[0] = 20; //replace with new values v[3] = 23; for(int j=0; j<v.size(); j++) //display vector contents cout << v[j] <<" " ; //20 11 12 23 cout << endl; getch(); return 0; } #include <conio.h> using namespace std; #include <iostream.h> #include <iostream> #include <vector> // demonstrates constructors, swap(), empty(), back(), pop_back() using namespace std; int main() { //an array of doubles int arr[] = { 23, 12, 113, 40 }; vector<int> v1(arr, arr+3); //initialize vector to array vector<int> v2(3); //empty vector of size 4 v1.swap(v2); //swap contents of v1 and v2 while( !v2.empty() ) //until vector is empty, { cout << v2.back() << " "; //display the last element v2.pop_back(); //remove the last element } cout << endl; getch(); return 0; } Örnek 12.3 #include <conio.h> using namespace std; #include <iostream.h> #include <iostream> #include <vector> int main() { int arr[] = { 100, 110, 120, 130 }; //an array of ints Karabük Üniversitesi Uzaktan Eğitim Araştırma ve Uygulama Merkezi Mühendislik Fakültesi No: 215 Balıklarkayası Mevkii 78050 Karabük TÜRKİYE
  • 3. BLM301 Mikroişlemciler 3 vector<int> v(arr, arr+4); //initialize vector to array cout <<"nBefore insertion:"; for(int j=0; j<v.size(); j++) //display all elements cout << v[j] <<" "; v.insert( v.begin()+2, 115); //insert 115 at element 2 cout <<"nAfter insertion:"; for(int j=0; j<v.size(); j++) //display all elements cout << v[j] <<" "; v.erase( v.begin()+2 ); //erase element 2 cout << "nAfter erasure:"; for(int j=0; j<v.size(); j++) //display all elements cout << v[j] << " "; cout << endl; getch(); return 0; } Örnek 12.4 #include <conio.h> using namespace std; #include <iostream.h> #include <iostream> //demonstrates push_front(), front(), pop_front() #include <list> int main() { list<int> ilist; ilist.push_back(30); //push items on back ilist.push_back(40); ilist.push_front(20); //push items on front ilist.push_front(10); int size = ilist.size(); //number of items for(int j=0; j<size; j++) { cout << ilist.front() <<" "; //read item from front ilist.pop_front(); //pop item off front } cout << endl; getch(); Karabük Üniversitesi Uzaktan Eğitim Araştırma ve Uygulama Merkezi Mühendislik Fakültesi No: 215 Balıklarkayası Mevkii 78050 Karabük TÜRKİYE
  • 4. BLM301 Mikroişlemciler 4 return 0;} #include <conio.h> using namespace std; #include <iostream.h> #include <iostream> //demonstrates push_front(), front(), pop_front() #include <list> int main() { int j; list<int> list1, list2; int arr1[] = { 40, 30, 20, 10 }; int arr2[] = { 15, 20, 25, 30, 35 }; for(j=0; j<4; j++) list1.push_back( arr1[j] ); //list1: 40, 30, 20, 10 for(j=0; j<5; j++) list2.push_back( arr2[j] ); //list2: 15, 20, 25, 30, 35 list1.reverse(); //reverse list1: 10 20 30 40 list1.merge(list2); //merge list2 into list1 list1.unique(); //remove duplicate 20 and 30 int size = list1.size(); while( !list1.empty() ) { cout << list1.front() << " "; //read item from front list1.pop_front(); //pop item off front } cout << endl; getch(); return 0; } Örnek 12.6 #include <conio.h> using namespace std; #include <iostream.h> #include <iostream> #include <deque> Karabük Üniversitesi Uzaktan Eğitim Araştırma ve Uygulama Merkezi Mühendislik Fakültesi No: 215 Balıklarkayası Mevkii 78050 Karabük TÜRKİYE
  • 5. BLM301 Mikroişlemciler 5 int main() { deque<int> deq; deq.push_back(30); //push items on back deq.push_back(40); deq.push_back(50); deq.push_front(20); //push items on front deq.push_front(10); deq[2] = 33; //change middle item for(int j=0; j<deq.size(); j++) cout << deq[j] << " "; //display items getch(); return 0; } Örnek 12.7 #include <conio.h> #include <iostream.h> #include <iostream> using namespace std; #include <vector> int main () { vector<int> v; for (int i=1; i<=15; i++) { v.push_back(i); } cout << "myvector contains:"; vector<int>::iterator it; for (it = v.begin() ; it != v.end(); ++it) cout << ' ' << *it; cout << 'n'; getch(); return 0; } Örnek 12.8 #include <conio.h> #include <iostream.h> Karabük Üniversitesi Uzaktan Eğitim Araştırma ve Uygulama Merkezi Mühendislik Fakültesi No: 215 Balıklarkayası Mevkii 78050 Karabük TÜRKİYE
  • 6. BLM301 Mikroişlemciler 6 #include <iostream> using namespace std; #include <vector> #include <list> int main() { int arr[] = { 2, 4, 6, 8 }; list<int> theList; for(int k=0; k<4; k++) //fill list with array elements { theList.push_back( arr[k] ); } list<int>::iterator iter; //iterator to list-of-ints for(iter = theList.begin(); iter != theList.end(); iter++) { cout << *iter << " "; } //display the list cout << endl; iter = theList.begin(); while( iter != theList.end() ) {cout << *iter++ << " ";} getch(); return 0; } Örnek 12.9 #include <conio.h> using namespace std; #include <iostream.h> #include <iostream> #include <list> #include <vector> int main () { list<int> mylist; list<int>::iterator it; // set some initial values: for (int i=1; i<=5; ++i) mylist.push_back(i); // 1 2 3 4 5 it = mylist.begin(); Karabük Üniversitesi Uzaktan Eğitim Araştırma ve Uygulama Merkezi Mühendislik Fakültesi No: 215 Balıklarkayası Mevkii 78050 Karabük TÜRKİYE
  • 7. BLM301 Mikroişlemciler 7 ++it; mylist.insert (it,10); // 1 10 2 3 4 5 for (it=mylist.begin(); it!=mylist.end(); ++it) { cout << ' ' << *it; } getch(); return 0; } struct agac { int kod; int mal; }; struct Acc { list<agac*>agaclistesi; list<Acc*>acclist; }; Acc * acc = new Acc(); Acc * acc1 = new Acc(); Acc * acc2 = new Acc(); int al(Acc* t) { t->agaclistesi.pop_back(); cout<<t->agaclistesi.size()<<endl; //4 //6 return 0; } int main () { agac * cam = new agac(); agac * kavak = new agac(); cam->kod=2; cam->mal=5; kavak->kod=9; kavak->mal=25; Karabük Üniversitesi Uzaktan Eğitim Araştırma ve Uygulama Merkezi Mühendislik Fakültesi No: 215 Balıklarkayası Mevkii 78050 Karabük TÜRKİYE
  • 8. BLM301 Mikroişlemciler 8 acc->agaclistesi.push_back(cam); acc->agaclistesi.push_back(kavak); acc->agaclistesi.push_back(cam); acc->agaclistesi.push_back(kavak); acc1->acclist.push_back(acc); acc1->acclist.push_back(acc); cout<<acc1->acclist.size()<<endl; //1 cout<< (acc1->acclist.front())->agaclistesi.size()<<endl; //2 acc2=acc1->acclist.front(); cout<<acc2->agaclistesi.size()<<endl;//3 al(acc1->acclist.front());//4 cout<<acc->agaclistesi.size()<<endl;//5 al(acc);//6 cout<<"son"<<endl; //7 getch(); return 0; } #include <conio.h> #include <iostream> #include <list> using namespace std; struct Acc { int id; int hop; Karabük Üniversitesi Uzaktan Eğitim Araştırma ve Uygulama Merkezi Mühendislik Fakültesi No: 215 Balıklarkayası Mevkii 78050 Karabük TÜRKİYE
  • 9. BLM301 Mikroişlemciler 9 list<Acc*>acclist; int al(Acc* a) { a->acclist.pop_back(); cout<<a->acclist.size()<<endl; return 0; } }; int main () { Acc * acc1 = new Acc(); Acc * acc2 = new Acc(); Acc * acc3 = new Acc(); acc1->id=1; acc1->hop=1; acc2->id=2; acc2->hop=1; acc3->id=3; acc3->hop=1; acc1->acclist.push_back(acc1); acc1->acclist.push_front(acc2); acc1->acclist.push_back(acc3); cout<<acc1->acclist.size()<<endl; //1 acc1->al(acc1); cout<< (acc1->acclist.front())->id<<endl; //2 getch(); return 0; Karabük Üniversitesi Uzaktan Eğitim Araştırma ve Uygulama Merkezi Mühendislik Fakültesi No: 215 Balıklarkayası Mevkii 78050 Karabük TÜRKİYE
  • 10. BLM301 Mikroişlemciler 10 } #include <conio.h> #include <iostream> #include <list> using namespace std; struct Acc { int id; int hop; list<Acc*>acclist; int al(Acc* a) { a->acclist.pop_back(); cout<<a->acclist.size()<<endl; return 0; } }; int main () { Acc * acc1 = new Acc(); Acc * acc2 = new Acc(); Acc * acc3 = new Acc(); acc1->id=1; acc1->hop=1; acc2->id=2; acc2->hop=2; acc3->id=3; acc3->hop=3; acc1->acclist.push_back(acc1); Karabük Üniversitesi Uzaktan Eğitim Araştırma ve Uygulama Merkezi Mühendislik Fakültesi No: 215 Balıklarkayası Mevkii 78050 Karabük TÜRKİYE
  • 11. BLM301 Mikroişlemciler 11 acc1->acclist.push_front(acc2); acc1->acclist.push_back(acc3); cout<<acc1->acclist.size()<<endl; list<Acc*>::iterator iter; iter = acc1->acclist.begin(); while( iter !=acc1->acclist.end() ) { cout << acc1->acclist.front()->id <<endl; cout << acc1->acclist.front()->hop <<endl; *iter++; acc1->acclist.pop_front(); } getch(); return 0; } Karabük Üniversitesi Uzaktan Eğitim Araştırma ve Uygulama Merkezi Mühendislik Fakültesi No: 215 Balıklarkayası Mevkii 78050 Karabük TÜRKİYE