Skip to content

This C++ project implements a dynamic array class for a list of strings, which allows you to create and manipulate an array of strings, featuring an undo method, which allows you to undo the operations on your array, including those like adding, deleting, and changing indexes of strings.

Notifications You must be signed in to change notification settings

Daksh2060/undo-stringlist-method

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 

Repository files navigation

String List Undo Method

This C++ project implements a dynamic array class called Stringlist, which allows you to create and manipulate an array of strings. The focus of the project is a special method of the Stringlist class called undo which allows the user to undo operations conducted on the Stringlist array. This allows users to dynamically manipulate a list of strings, such as adding, removing, copying, and shifting strings, and undoing these operations as they see fit.

Features

  • Insertion and Deletion: Stringlist allows the insertion of a string at any position within the array, via insert_front, insert_back, insert_before, and insert_after. Likewise, can also delete a specific string with remove_first, remove at a specific index with remove_at, or empty the string list with remove_all.

  • Assignment: Can use the custom assignment class operator = to set a string list equal to another, as well as copying the undo sequence. (For more detail see code comments)

  • Searching: Can also find the index of a specific word within the array using index_of, or verify the existence of a specific string in the list using contains.

  • Undo: The undo method allows a user to undo their last manipulation to the string list. The method keeps track of all actions done on a string list in a sibling stack, allowing the user to undo every action even after several manipulations. It's essentially a CTRL + Z that you can use dynamically in running programs.

How does it work?

The undo method works by using a set of counter operations in response to every action. Every time something is done to the string list, a private stack takes note of what action was done using a series of keywords. When undo is called, the stack is popped, and the corresponding keyword is associated with an inverse operation that cancels out that action. For example, if an item is added to the back of the list, the stack notes the key phrase UNDO_INSERT_BACK, and when undo is called, this keyphrase is read and the string list removes the last item. This applies to all non-idempotent operations available.

Installation and Use

Follow these steps to set up and run Stringlist in C++:

  1. Clone the repository to your local machine:

    git clone https://github.com/Daksh2060/undo-method-cpp
  2. If using the provided test file to usage, use the provided makefile:

    make test
    ./test
  3. To include in your own file, include the header in your project:

    #include "undo.h"
  4. To use the class, you must create a string list, named list1 in this example :

    Stringlist list1;
  5. You can then manipulate this list using class methods, for example:

    list1.insert_back("Hello");

    For the full list of methods, see the public Stringlist class in undo.h

  6. To undo the last operation, call undo:

    list1.undo();

Contact

Feel free to reach out if you have any questions, suggestions, or feedback:

About

This C++ project implements a dynamic array class for a list of strings, which allows you to create and manipulate an array of strings, featuring an undo method, which allows you to undo the operations on your array, including those like adding, deleting, and changing indexes of strings.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages