Ma’lumotlar tuzulmasi va Algoritmlash (ma’ruza) fanidan Mustaqil ish
while (second_last->next->next != NULL) second_last = second_last->next; // Delete the last node delete
Download 271.88 Kb.
|
Mavzu Chiziqli ikki bog’lamli ro’yxatlar va ularni dasturda ama
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 "< cout << temp->data << "-->"; if(temp == NULL) cout<<"NULL"< head = deleteFirstNode(head); cout<<"Linked list after deleting head node"< cout << temp->data << "-->"; if(temp == NULL) cout<<"NULL"< head = removeLastNode(head); cout<<"Linked list after deleting last node"< 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.
Chiqish: Bog'langan ro'yxat yaratildi: 9–>7–>5–>3–>1– >null Bosh tugunni o'chirishdan keyin bog'langan ro'yxat: 7–>5–>3–>1– >null Oxirgi tugunni o'chirishdan keyin bog'langan ro'yxat: 7–>5–>3–>null Download 271.88 Kb. Do'stlaringiz bilan baham: |
Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling
ma'muriyatiga murojaat qiling