Elementni n pozitsiyaga siljitish dasturini tuzing
Download 18.13 Kb.
|
3-labaratoriya ishi
Elementni n pozitsiyaga siljitish dasturini tuzing. #include using namespace std; class Jism { public:
int son; Jism* keyingi; };
int soni = 0; Jism* boshi = NULL; Jism* davomi = NULL; bool boldi = false;
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;
yangi -> son = butun; yangi -> keyingi = NULL;
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; }
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 --;
bir = yangi -> son; cout << "Birinchi:" << bir << "\n"; }
if (tr < 0) d ++;
} else d ++;
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; }
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 (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'muriyatiga murojaat qiling