Implementation of contact book using linked list

Managing contacts effectively is crucial for staying connected in today's fast-paced world. Whether it's personal or professional relationships, having a centralized system to store and retrieve contact information can make a significant difference. To address this need, I have developed the Contact Book Application—a command-line program built using C++. In this blog post, I will provide an overview of the Contact Book Application, explain how it works, and share insights into its programming methodology and algorithms. Let's dive in!

Overview

At its core, the Contact Book Application leverages a linked list data structure to store contact details. Each contact is represented as a node in the linked list, containing essential fields such as name, phone number, email address, and physical address. By using a linked list, the Contact Book Application enables dynamic storage allocation, efficient insertion and deletion, and flexible access to contact data.

How to use

Getting started with the Contact Book Application is straightforward. Just follow these simple steps:

  1. Clone the Contact Book Application repository from GitHub.

  2. Compile the provided C++ code using a suitable compiler.

  3. Run the compiled executable file to start the Contact Book Application.

  4. You will be presented with a user-friendly menu that lists available operations.

  5. Choose an operation by entering the corresponding number from the menu.

  6. Follow the on-screen prompts to perform the selected operation, such as adding a contact or searching for a contact.

  7. After completing an operation, you will be returned to the main menu to choose another option.

  8. To exit the application, select the "Exit" option from the menu.

Adding new contact

Adding a Contact

When adding a new contact, the Contact Book Application follows these steps:

  1. Allocate memory for a new contact node.

  2. Prompt the user to enter the contact details, including name, phone number, email address, and physical address.

  3. Validate the entered data to ensure it meets specific criteria, such as using regular expressions for proper formatting.

  4. If the linked list is empty, set the new node as the head of the linked list.

  5. If the linked list is not empty, traverse it to find the last node.

  6. Attach the new node to the last node's "next" pointer, effectively adding it to the end of the linked list.

  7. Inform the user that the contact has been added successfully.

Deleting contact

The Contact Book Application allows users to delete contacts based on various criteria, such as phone number, email address, or physical address. The deletion process involves the following steps:

  1. Prompt the user to select the type of contact information they want to delete.

  2. Depending on the selection, prompt the user to enter the corresponding information for the contact to be deleted.

  3. Search the linked list for a contact that matches the entered information.

  4. If a matching contact is found, remove it from the linked list by adjusting the appropriate pointers.

  5. If no matching contact is found, display a "not found" message to the user.

Searching for a Contact

The Contact Book Application facilitates easy searching for specific contacts using various search criteria, such as name, phone number, email address, or physical address. The search functionality works as follows:

  1. Prompt the user to select the type of contact information they want to search for.

  2. Depending on the selection, prompt the user to enter the corresponding information to search for.

  3. Traverse the linked list, comparing the entered information with the contact details in each node.

  4. If a matching contact is found, display its details to the user.

  5. If no matching contact is found, display a "not found" message.

Displaying contacts

To provide an overview of all contacts stored in the Contact Book Application, the "Display Contacts" functionality performs the following steps:

  1. Traverse the linked list starting from the head node.

  2. For each node encountered, display the contact details, including name, phone number, email address, and physical address.

  3. Repeat the process until all contacts have been displayed.

Programming Methodology

The Contact Book Application follows a structured and modular programming approach. It leverages the power of the C++ language to ensure efficiency and maintainability. Some notable programming methodologies and techniques used in the application include:

  • Linked List Data Structure: The application utilizes a linked list to store contact information efficiently. This dynamic data structure allows for seamless insertion, deletion, and traversal of contacts.

  • Regular Expressions: Regular expressions are employed to validate user input and ensure the correctness of contact details, such as name formatting, phone number structure, email address validity, and address formatting.

  • User Input Handling: The application employs proper input handling techniques to provide a seamless user experience, preventing unexpected behavior and handling invalid input gracefully.

  • Code Reusability: The Contact Book Application employs functions and modular code design to enhance code reusability and maintainability. Each functionality, such as adding, deleting, and searching for contacts, is implemented as a separate function, promoting code organization and reusability.

Conclusion

The Contact Book Application offers an efficient and user-friendly solution for managing contact information. By leveraging a linked list data structure and implementing well-designed algorithms, the application ensures optimal performance for various contact operations. Whether you need to add, delete, search for, or display contacts, the Contact Book Application has you covered.

Feel free to explore and enhance the Contact Book Application according to your specific requirements. Its modular code design and adherence to programming best practices make it an excellent starting point for further customization.

Contact Book Application Repository: GitHub