|
Stack konteyneri // Stack 290422. cpp : main project file
|
Sana | 13.06.2022 | Hajmi | 29,7 Kb. | | #664611 |
| Bog'liq Stack konteyneri 290422 (1)
Stack konteyneri
// Stack_290422.cpp : main project file.
#include "stdafx.h"
#include
#include
#include
#include
#include
using namespace System;
using namespace std;
int main(array ^args)
{
//srand(time(NULL));
stack st;
int n = 7;//sikl elementlarini kiritish uchun
int s;//stack uchun
for (int i = 0; i < n; i++)
{
s = rand() % 21 - 10;//-10,10
st.push(s);//stackka ei-t qoshish
cout << st.top() << " ";//choqqi el-ti
}
cout << endl;
cout << " Dastlabki element->" << st.top() << endl;
cout << "Elementlar soni->" << st.size() << endl;
cout << " Stackni top elementini o'chiramiz->" << endl;
st.pop();//elementni o'chirish
cout << " Dastlabki element->" << st.top() << endl;
while (!st.empty())
{
cout << st.top() << " ";
st.pop();//ekranga chiqqan elementini ochirish
}
system("pause");
return 0;
}
Kiritilgan eng uzun familiyani va max qiymatini chiqaish
int main(array ^args)
{
stack st;
int n; cout << "n=";
cin >> n;
string s;
cout << n << " ta familiyani kiriting" << endl;
for (int i = 0; i < n; i++)
{
cin >> s;
st.push(s);//stackka ei-t qoshish
}
int f_max = 0;//familiyasi max
while (!st.empty())
{
if (st.top().length()>f_max)
{
f_max = st.top().length();
s = st.top();
}
st.pop();
}
cout << " Eng uzun familiya:" << s << endl;
cout << " Eng uzun familiya uzunligi:" << f_max << endl;
}
Kiritilgan eng uzun familiyani olib tashlash va qayta chiqaish
int main(array ^args)
{
stack st;
dequeds;
int n; cout << "n=";
cin >> n;
string s,s1;
int joy;
int f_max = 0;
cout << n << " ta familiyani kiriting" << endl;
for (int i = 0; i < n; i++)
{
cin >> s;
st.push(s);//stackka ei-t qoshish
ds.push_back(s);//dekka yozvotti
if (st.top().length()>f_max)
{
joy = i;
s1 = st.top();
f_max = st.top().length();
}
}
ds.erase(ds.begin() + joy);
while (!st.empty())
{
st.pop();
}
cout << " Eng uzun familiyani o'chirilgandan keyin:" << endl;
for (auto it = ds.begin(); it != ds.end(); it++)
{
st.push(*it);
}
while (!st.empty())
{
cout << st.top() << endl;
st.pop();
}
cout << " Eng uzun familiya:" << s1 << endl;
cout << " Eng uzun familiya uzunligi:" << f_max << endl;
}
Stackning maximum elementi topilsin.
//Stek elementlarini ko'rsatuvchi funksiya
void stackElementlari(stack s)
{
while (!s.empty())
{
cout << '\t' << s.top();
s.pop();
}
cout << '\n';
}
//Stekdan max elementni topuvchi funksiya
int maxElement(stack s){
int max = s.top();
while (!s.empty())
{
if(s.top() > max)
{
max = s.top();
}
s.pop();
}
return max;
}
//Asosiy funksiya
int main ()
{
stack s;
s.push(101);
s.push(30);
s.push(20);
s.push(5);
s.push(100);
cout << "Stek elementlari: ";
stackElementlari( s);
int max = maxElement (s);
cout << "\nEng katta element: " << max;
return 0;
}
2-usul(max)
// Stack_290422.cpp : main project file.
#include "stdafx.h"
#include
#include
#include
#include
#include
#include
using namespace System;
using namespace std;
//Stek elementlarini ko'rsatuvchi funksiya
void chiqare(stack st,int &Max)
{
Max = st.top();
while (st.size()!=0)
{
if (st.top() > Max)
Max = st.top();
cout << "\t" << st.top();
st.pop();
}
cout << "\n";
}
//Asosiy funksiya
int main()
{
srand(time(0));
stack st;
int son;
int Mx;
while (1)
{
son = rand() % 11 + 10;
st.emplace(son);
if (st.top() == 13)
break;
}
cout << " Stack elementlari:";
chiqare(st, Mx);
printf(" Stackning maxsimal elementi=: %d\n", Mx);
system("pause");
return 0;
}
Navbat konteyneri
int main(array ^args)
{
queue q;
int n; cout << " n=";
cin >> n;
float son;
cout << n << " ta haqiqiy son kiriting" << endl;
for (int i = 0; i < n; i++)
{
cout << i + 1 << "-son>" << endl;
cin >> son;
q.push(son);
}
cout << " Dastlabki element->" << q.front() << endl;
cout << " Oxirgi element->" << q.back() << endl;
cout << " Elementlar soni->" << q.size() << endl;
q.pop();
cout << "O'chirilgandan keyingi dastlabki element->" << q.front() << endl;
while (!q.empty())
{
cout << q.front() << " " << endl;
q.pop();
}
system("pause");
return 0;
}
Stackni dequega almashtirish
#include "stdafx.h"
#include
#include
#include
#include
using namespace std;
void showx(stack st){
stack yor=st;
for(;!yor.empty();){
cout<yor.pop();
}
cout<}
int main(array ^args)
{ srand(time(NULL));
stack st;
int n, a; cin>>n;
for(int i=0; i{
a=rand()%20;
st.push(a);
}
showx(st);
cout<<"\n size = "<cout<<"st top = "<auto w=st._Get_container();
cout<<"Satckning ortadagi elementi "<system("pause");
return 0;
}
// stack, queue.cpp : main project file.
#include "stdafx.h"
#include
#include
#include
#include
using namespace std;
void showx(stack st){
stack yor=st;
for(;!yor.empty();){
cout<yor.pop();
}
cout<}
int main(array ^args)
{ srand(time(NULL));
stack st;
int n, a; cin>>n;
for(int i=0; i{
a=rand()%20;
st.push(a);
}
showx(st);
cout<<"\n size = "<cout<<"st top = "<auto w=st._Get_container();
cout<<"Satckning ortadagi elementi "<system("pause");
return 0;
}
// stack, queue.cpp : main project file.
#include "stdafx.h"
#include
#include
#include
#include
#include
using namespace std;
class kliyent{
public:
string FISH;
string maqsadi;
void kirit(){
cin.ignore();
cout<<"FISH: "; getline(cin,FISH);
cout<<"Maqsadi: "; cin>>maqsadi;
}
void chiqar(){
cout< " <}
};
void showx(queue st){
queue yor=st;
for(;!yor.empty();){
yor.front().chiqar();
yor.pop();
}
cout<}
int main(array ^args)
{ srand(time(NULL));
queue navbat;
int n, a; cin>>n;
kliyent k;
for(int i=0; i{
k.kirit();
navbat.push(k);
}
showx(navbat);
cout<<"\n size = "<cout<<"Kim oxiri = "; navbat.back().chiqar();
cout<<"\n\n";
auto w=navbat._Get_container();
//cout<<"Satckning ortadagi elementi "<for(auto h:w){
if(h.maqsadi=="abmen") h.chiqar();
}
system("pause");
return 0;
}
Do'stlaringiz bilan baham: |
|
|