Mustaqil ish Mavzu: Chiziqli ikki bog’lamli ro’yxatlar va ularni dasturda amalga oshirish Bajardi: Sobirov U. Guruh: tt2M21-01 Mavzu: Chiziqli ikki bog’lamli ro’yxatlar va ularni dasturda amalga oshirish Reja
while (second_last->next->next != NULL) second_last = second_last->next; // Delete the last node delete
Download 341.5 Kb.
|
while (second_last->next->next != NULL)
second_last = second_last->next; // Delete the last node delete (second_last->next); // set next of second_last to null second_last->next = NULL; return head; } // create linked list by adding nodes at head void push(struct Node** head, int new_data) { struct Node* newNode = new Node; newNode->data = new_data; newNode->next = (*head); (*head) = newNode; } // main function int main() { /* Start with the empty list */ Node* head = NULL; // create linked list push(&head, 2); push(&head, 4); push(&head, 6); push(&head, 8); push(&head, 10); Node* temp; cout<<"Linked list created "< temp = temp->next) cout << temp->data << "-->"; if(temp == NULL) cout<<"NULL"< head = deleteFirstNode(head); cout<<"Linked list after deleting head node"< NULL; temp = temp->next) cout << temp->data << "-->"; if(temp == NULL) cout<<"NULL"< head = removeLastNode(head); cout<<"Linked list after deleting last node"< NULL; temp = temp->next) cout << temp->data << "-->"; if(temp == NULL) cout<<"NULL"; return 0; } Chiqish: Bog'langan ro'yxat yaratildi 10–>8–>6–>4–>2– >NULL Bosh tugunni o'chirishdan keyin bog'langan ro'yxat 8–>6–>4–>2– >NULL Oxirgi tugunni o'chirishdan keyin bog'langan ro'yxat 8–>6–>4–>NULL Keyingi - bog'langan ro'yxatdagi tugunlarni o'chirish uchun Java dasturi. Amalga oshirish mantig'i C++ dasturida qo'llaniladigan mantiq bilan bir xil. Faqatgina farq shundaki, bog'langan ro'yxat sinf sifatida e'lon qilinadi.
Download 341.5 Kb. Do'stlaringiz bilan baham: |
Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling
ma'muriyatiga murojaat qiling