Coder Social home page Coder Social logo

doublylinkedlistdemo's Introduction

Doubly Linked List Demo

Requirements

Design and implement a class representing an unsorted doubly linked list. The class must have the following requirements:

  1. The linked list and the nodes must be implemented as C++ templates
  2. It must include a constructor, a destructor, a copy constructor and an operator=
  3. It must include functions to delete a given item, search for a given item, check if the list is empty, return the length of the list
  4. It must include functions to insert at the front and at the back of the list
  5. It must provide an iterator to access items from front to back
  6. It must provide an iterator to access items from back to front

Write a menu-driven program to test all the functions in your class.

Run the code

# Compile
$ g++ -std=c++11 main.cpp -o DoublyLinkedListDemo
# Run
$ ./DoublyLinkedListDemo

Menu:
1. Insert at front
2. Insert at back
3. Delete item
4. Search item
5. Show forward
6. Show backward
0. Exit
Enter choice: 1
Enter item to insert at the front: 100

Menu:
1. Insert at front
2. Insert at back
3. Delete item
4. Search item
5. Show forward
6. Show backward
0. Exit
Enter choice: 3
Enter item to delete: 100
Item deleted.

Menu:
1. Insert at front
2. Insert at back
3. Delete item
4. Search item
5. Show forward
6. Show backward
0. Exit
Enter choice: 3
List is empty. Nothing to delete!

Menu:
1. Insert at front
2. Insert at back
3. Delete item
4. Search item
5. Show forward
6. Show backward
0. Exit
Enter choice: 4
List is empty. Nothing to search for!

Menu:
1. Insert at front
2. Insert at back
3. Delete item
4. Search item
5. Show forward
6. Show backward
0. Exit
Enter choice: 5
Length of the list: 0


Menu:
1. Insert at front
2. Insert at back
3. Delete item
4. Search item
5. Show forward
6. Show backward
0. Exit
Enter choice: 6
Length of the list: 0


Menu:
1. Insert at front
2. Insert at back
3. Delete item
4. Search item
5. Show forward
6. Show backward
0. Exit
Enter choice: 1
Enter item to insert at the front: 200

Menu:
1. Insert at front
2. Insert at back
3. Delete item
4. Search item
5. Show forward
6. Show backward
0. Exit
Enter choice: 1
Enter item to insert at the front: 100

Menu:
1. Insert at front
2. Insert at back
3. Delete item
4. Search item
5. Show forward
6. Show backward
0. Exit
Enter choice: 2
Enter item to insert at the back: 300

Menu:
1. Insert at front
2. Insert at back
3. Delete item
4. Search item
5. Show forward
6. Show backward
0. Exit
Enter choice: 4
Search the list for a given item: 300
Item found in the list.

Menu:
1. Insert at front
2. Insert at back
3. Delete item
4. Search item
5. Show forward
6. Show backward
0. Exit
Enter choice: 400
Invalid choice!

Menu:
1. Insert at front
2. Insert at back
3. Delete item
4. Search item
5. Show forward
6. Show backward
0. Exit
Enter choice: 4
Search the list for a given item: 400
Item not found in the list.

Menu:
1. Insert at front
2. Insert at back
3. Delete item
4. Search item
5. Show forward
6. Show backward
0. Exit
Enter choice: 5
Length of the list: 3
100 200 300 

Menu:
1. Insert at front
2. Insert at back
3. Delete item
4. Search item
5. Show forward
6. Show backward
0. Exit
Enter choice: 6
Length of the list: 3
300 200 100 

Menu:
1. Insert at front
2. Insert at back
3. Delete item
4. Search item
5. Show forward
6. Show backward
0. Exit
Enter choice: 0

doublylinkedlistdemo's People

Contributors

qingquan-li avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.