Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include"Dog.h"
- void insertDog(Dog *&head);
- void displayList(Dog *&head);
- void deleteList(Dog *&head);
- int main()
- {
- Dog *head = NULL;
- int count = 0;
- cout << "Enter dogs into the list: " << endl;
- char anotherOne = 'Y';
- while (anotherOne == 'Y' || anotherOne == 'y')
- {
- insertDog(head);
- cout << "Enter another Dog (Y or N)? ";
- cin >> anotherOne;
- }
- char answer = 'y';
- while (answer == 'y' || answer == 'Y')
- {
- cout << "Display the list (Y/N)?";
- cin >> answer;
- system("cls");
- cout << "Here is the list:\n";
- displayList(head);
- }
- cout << "Here is the list after the delete: " << endl;
- deleteList(head);
- system("pause");
- return 0;
- }
- void insertDog(Dog *&head)
- {
- Dog *temp = new Dog;
- cout << "ID: ";
- cin >> temp->id;
- cin.ignore();
- cout << "Name: ";
- getline(cin, temp->name);
- temp->next = head;
- head = temp;
- }
- void displayList(Dog *&head)
- {
- Dog *temp = head;
- while (temp != NULL)
- {
- cout << "ID: " << temp->id << endl;
- cout << "Name " << temp->name << endl;
- temp = temp->next;
- }
- }
- void deleteList(Dog *&head)
- {
- Dog *lead = head;
- Dog *follow = head;
- int idNum;
- cout << "Enter an id of a dog to be deleted: ";
- cin >> idNum;
- while ((lead->next != NULL) && (lead->id != idNum))
- {
- follow = lead;
- lead = lead->next;
- }
- if (lead == NULL)
- cout << "Id was not found." << endl;
- else
- follow->next = lead->next;
- if (lead->next == NULL)
- {
- follow->next = NULL;
- delete lead;
- }
- else
- delete lead;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement