Callections
Set
HashSet
Map
Queue
Tasks
Largest Even Number
Quyidagi list dan eng katta juft sonni toping.
[12, 3, 34, 56, 11, 32, 45, 11, 43]
Bubble Sort
Quyidagi list ni “Bubble Sort” orqali o`sish tartibida joylashtiring.
[12, 3, 34, 56, 11, 32, 45, 11, 43]
Set Maximum
Quyidagi set ning maximum elementini topadigan kod yozing.
Set set = Set.from([12, 23, -98, 45, 6]);
Set Mismatch
[1,2,3,4] deb yozmoqchi bo`ldik lekin xató yozib [1,2,2,4] deb yozdik. Bu yerda xató ketgan raqamni topadigan kod yozing. Va bu masalani SET dan foydalib yeching.
[1,2,2,4] => 2 chiqishi kerak. (3 bolishi kerak edi 2 deb xató yozdik).
Reverse Queue
Q2 ga Q1 ni teskari tartibda joylashtiring. Shart: queue ning standart metodlaridan foydalanib.
Queue q1 = new Queue();
q.addAll([12, 23, 34, 45, 67]);
Queue q2 = new Queue();
Generics
Generics
Generic 1
Generic 2
Generic 3
Tasks
Task 1
Quyidagi 3 xil turdagi list ning oxirgi elementini qaytaradigan Generic funksiya yarating.
List list1 = [12, 23, 34];
List list2 = [12.12, 23.23, 34.34];
List list3 = ["PDP", "Online", "2020"];
Task 2
Map map1 = {1: 111,2: 222,};
Map map2 = {"name": "Tom","age": "25"};
Ushbu 2 xil turdagi Map berilgan bo`lsa quyidagicha Console ga chop qiladigan yagona printMap() deb nomlangan Generic funksiya yozing.
Key: name, Value: Tom
Key: age, Value: 25
Key: 1, Value: 111
Key: 2, Value: 222
Task 3
Har qanday tipdagi Queue ni teskarisini topadigan Generic funksiya yozing.
Queue reverse(Queue que) {
…
return que;
}
Example:
{2020, PDP, Online, Flutter} => {Flutter, Online, PDP, 2020}
Dostları ilə paylaş: |