Elementni n pozitsiyaga siljitish dasturini tuzing


Download 18.13 Kb.
Sana02.01.2022
Hajmi18.13 Kb.
#196898
Bog'liq
3-labaratoriya ishi


  1. Elementni n pozitsiyaga siljitish dasturini tuzing.

#include

using namespace std;


class Jism {

public:


int son;

Jism* keyingi;

};
int main() {

int soni = 0;

Jism* boshi = NULL;

Jism* davomi = NULL;

bool boldi = false;
for (int i = 1; i <= 6; i ++) {

Jism* yangi = new Jism;

yangi -> son = i;

yangi -> keyingi = NULL;


if (boshi == 0) {

boshi = yangi;

davomi = yangi;

}

davomi -> keyingi = yangi;



davomi = yangi;

soni ++;


}
while (true) {

cout << "1. Ro`yxatga element qo`sish. " << "(" << soni << ")" << endl;

cout << "2. Elementni siljitish. " << endl;

cout << "Chiqish uchun X ni bosing." << endl;

int n;

cout << "Kiriting: "; cin >> n;


if (n == 1) {

int butun;

cout << "Butun son kiriting: "; cin >> butun;
Jism* yangi = new Jism;

yangi -> son = butun;

yangi -> keyingi = NULL;
if (boshi == 0) {

boshi = yangi;

davomi = yangi;

}

davomi -> keyingi = yangi;



davomi = yangi;

soni ++;
}


if (n == 2) {

system("cls");

cout << "Ro`yxatda " << soni << " ta element bor:\n";

Jism* yangi = boshi;

while (true) {

cout << yangi -> son << " ";

if (yangi -> keyingi == 0)

break;


yangi = yangi -> keyingi;

}
if (!boldi) {


int tr, qancha;

cout << "\n" << "Siljitish uchun element tartib raqamini tanlang: "; cin >> tr;

cout << "Qancha siljitish kerak (+-): "; cin >> qancha;

yangi = boshi;


if (tr + qancha <= soni && (tr + qancha > 0)) {

boldi = true;

int bir, D = 0, d = 0, T = tr;

while (true) {

tr --;
if (tr == 0) {

bir = yangi -> son;

cout << "Birinchi:" << bir << "\n";

}
if (qancha > 0) {

if (tr < 0)

d ++;


} else

d ++;
if (qancha > 0) {

if (d == qancha) {

D = yangi -> son;

cout << "Ikkinchi:" << D << "\n";

}

} else {



if (d == T + qancha) {

D = yangi -> son;

cout << "Ikkinchi:" << D << "\n";

}

}


if (yangi -> keyingi == 0)

break;


yangi = yangi -> keyingi;

}
tr = T;

d = 0;

yangi = boshi;



bool b = false;

boshi = NULL;

davomi = NULL;

while (true) {

tr --;

Jism* yangilar = new Jism;


if (tr == 0) {

cout << D << " ";

//boshi -> son = D;

yangilar -> son = D;

yangilar -> keyingi = NULL;

b = true;

}
if (qancha > 0) {

if (tr < 0)

d ++;

} else


d ++;
if (qancha > 0) {

if (d == qancha) {

cout << bir << " ";

//boshi -> son = bir;

yangilar -> son = bir;

yangilar -> keyingi = NULL;

} else {

if (!b) {

cout << yangi -> son << " ";

yangilar -> son = yangi -> son;

yangilar -> keyingi = NULL;

}

if (b)



b = false;

}

} else {



if (d == T + qancha) {

cout << bir << " ";

//boshi -> son = bir;

yangilar -> son = bir;

yangilar -> keyingi = NULL;

} else {


if (!b) {

cout << yangi -> son << " ";

yangilar -> son = yangi -> son;

yangilar -> keyingi = NULL;

}

if (b)


b = false;

}

}


if (boshi == 0) {

boshi = yangilar;

davomi = yangilar;

}

davomi -> keyingi = yangilar;



davomi = yangilar;
if (yangi -> keyingi == 0)

break;


yangi = yangi -> keyingi;

}} else {

cout << "Xato ma`lumot kiritilgan\n";

}

}



system("pause");
}

system("CLS");



}

}

Download 18.13 Kb.

Do'stlaringiz bilan baham:




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