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


Download 1.77 Mb.
bet8/8
Sana04.12.2020
Hajmi1.77 Mb.
#159443
1   2   3   4   5   6   7   8
Bog'liq
Lab 4




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 ©fayllar.org 2024
ma'muriyatiga murojaat qiling