Ton respublikasi axborot texnologiyalari va kommunikatsiya rivojlanish vazirligi muhammad al-xorazmiy nomidagi toshkent axborot texnologiyalari universiteti



Download 1,77 Mb.
bet8/8
Sana17.07.2021
Hajmi1,77 Mb.
#121781
1   2   3   4   5   6   7   8
Bog'liq
Lab 4

Dastur kodi

#include

using namespace std;

class Node{

public: int number;

Node* next;

};

int main()

{ Node* head = NULL;

Node* lastPtr = NULL;

short action = -1;

while (1)

{ cout<<"1. element qo’shish\n";

cout<<"2. ro’yhatni ko’rish\n";

cout<<"3. ro’yhat maksimalini topish\n";

cout<<"0. chiqish\n\n";

cout<<"tanlang: ";

cin>>action;

if (action == 0) {

system("CLS");

break;}

if (action == 1)

{ system("CLS");

Node* ptr = new Node;

int numb = -1;

cout<<"son kiriting: ";

cin>>numb;

ptr->number = numb;

ptr->next = NULL;

if (head == 0)

{ head = ptr;

lastPtr = ptr;

system("CLS");

continue;

}

lastPtr->next = ptr;

lastPtr = ptr;

system("CLS");

continue;

}

if (action == 2){

Node* ptr = NULL;

system("CLS");

if (head == 0)

{ cout<<"\t!!! ro’yhat bo’sh !!!\n\n";

system("PAUSE");

system("CLS");

continue;

}

cout<<"* * * * * ro’yhat * * * * *\n\n";

ptr = head;

while (1) {

cout<
number<<" ";


if (ptr->next == 0) break;

ptr = ptr->next;

}

cout<<"\n\n";

system("PAUSE");

system("CLS");

continue;

}

if (action == 3)

{

system("CLS");

Node* p = head;

Node* q = new Node;

Node* last = new Node;

int max=p->number; q=head;

while(p){

if(max
number){ max=p->number;}


p=p->next;

}

system("CLS");

cout<<"max="<

system("pause");

continue;

}

}}

Dastur bajarilishi natijasi

  1. element qo’shish

  2. ro’yhatni ko’rish

  3. ro’yhat maksimalini topish

  1. chiqish

tanlang:1

{1,2,3,55,4,6} sonlari kiritildi. 2-holat tanlanganda natija:



*****ro’yhat*****

1 2 3 55 4 6

3-holat tanlanganda natija:



max=55

Topshiriq

16.O’quvchilar familiyalari va imtihon biletlari raqamlaridan tashkil topgan 2 ta halqasimon ro’yhat berilgan. O’quvchilar tomonidan olingan bilet raqamlari aniqlansin. Imtihon biletlari uchun qayta hisoblash soni - E, o’quvchilar uchun esa - K.











Dastur kodi :

#include

using namespace std;

struct Node{

string data;

struct Node *next;

};

struct Nodee{



int datta;

struct Nodee *next;

};

void insert(Node** head_ref,string new_data) {



Node* new_node = new Node();

new_node->data = new_data;

new_node->next = (*head_ref);

(*head_ref) = new_node;

}

void insertint(Nodee** head_ref,int new_data) {



Nodee* new_node = new Nodee();

new_node->datta = new_data;

new_node->next = (*head_ref);

(*head_ref) = new_node;

}

string getN(Node* head,int index) {



struct Node* ptr;

ptr = head;

int count = 0;

do {


if(count == index){

return (ptr->data);

}

count++;


ptr = ptr->next;

} while(ptr != head);

return "";

}

int getiNt(Nodee* head,int index) {



struct Nodee* ptr;

ptr = head;

int count = 0;

do {


if(count == index){

return (ptr->datta);

}

count++;


ptr = ptr->next;

} while(ptr != head);

return -1;

}

int random(int min, int max) //range : [min, max)



{

static bool first = true;

if (first)

{


srand( time(NULL) ); //seeding for the first time only!

first = false;

}

return min + rand() % (( max + 1 ) - min);



}

int main(){

Node* firstListHead = NULL;

Nodee* secondListHead = NULL;

insert(&firstListHead,"Farhod");

insert(&firstListHead,"Shohjahon");

insert(&firstListHead,"Murodjon");

insert(&firstListHead,"Muhammadaziz");

insert(&firstListHead,"Sardor");

insertint(&secondListHead,2);

insertint(&secondListHead,1);

insertint(&secondListHead,4);

insertint(&secondListHead,5);

insertint(&secondListHead,3);

int min = 0;

int max = 4;

for(int i=0;i<5;i++){

int firstListRandIndex = random(min,max);

int secondListRandIndex = random(min,max);

cout << "1-Royxatdan : " << getN(firstListHead,firstListRandIndex) << endl;

cout << "Bilet nomeri : " << getiNt(secondListHead,secondListRandIndex)<

}

}



Xulosa : Men ushbu labaratoriya ishini bajarish mobaynida dinamik ma`lumotlar tuzilmasini, ularni klassifikasiyasini, chiziqli bir tomonlama yo`nalgan ro`yxatlar bilan ishlashni, dinamik ma`lumotlar tuzilmasini algoritmlashni o`rgandim.
Download 1,77 Mb.

Do'stlaringiz bilan baham:
1   2   3   4   5   6   7   8




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish