diff --git a/CMakeLists.txt.user b/CMakeLists.txt.user new file mode 100644 index 0000000..a97fe25 --- /dev/null +++ b/CMakeLists.txt.user @@ -0,0 +1,343 @@ + + + + + + EnvironmentId + {fbf10818-29d5-4e1d-8edb-97a4edab83ae} + + + ProjectExplorer.Project.ActiveTarget + 0 + + + ProjectExplorer.Project.EditorSettings + + true + false + true + + Cpp + + CppGlobal + + + + QmlJS + + QmlJSGlobal + + + 2 + UTF-8 + false + 4 + false + 80 + true + true + 1 + true + false + 0 + true + true + 0 + 8 + true + 1 + true + true + true + false + + + + ProjectExplorer.Project.PluginSettings + + + true + + + + ProjectExplorer.Project.Target.0 + + Desktop + Desktop + {33d8d843-88e7-4164-aae1-c402cebdeb61} + 0 + 0 + 0 + + + CMAKE_BUILD_TYPE:STRING=Debug + + /home/eduardo/Projects/build-linked-lists-Desktop-Debug + + + + + all + + true + CMake Build + + CMakeProjectManager.MakeStep + + 1 + Build + + ProjectExplorer.BuildSteps.Build + + + + + + clean + + true + CMake Build + + CMakeProjectManager.MakeStep + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Debug + Debug + CMakeProjectManager.CMakeBuildConfiguration + + + + CMAKE_BUILD_TYPE:STRING=Release + + /home/eduardo/Projects/build-linked-lists-Desktop-Release + + + + + all + + true + CMake Build + + CMakeProjectManager.MakeStep + + 1 + Build + + ProjectExplorer.BuildSteps.Build + + + + + + clean + + true + CMake Build + + CMakeProjectManager.MakeStep + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Release + Release + CMakeProjectManager.CMakeBuildConfiguration + + + + CMAKE_BUILD_TYPE:STRING=RelWithDebInfo + + /home/eduardo/Projects/build-linked-lists-Desktop-Release-with-Debug-Information + + + + + all + + true + CMake Build + + CMakeProjectManager.MakeStep + + 1 + Build + + ProjectExplorer.BuildSteps.Build + + + + + + clean + + true + CMake Build + + CMakeProjectManager.MakeStep + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Release with Debug Information + Release with Debug Information + CMakeProjectManager.CMakeBuildConfiguration + + + + CMAKE_BUILD_TYPE:STRING=MinSizeRel + + /home/eduardo/Projects/build-linked-lists-Desktop-Minimum-Size-Release + + + + + all + + true + CMake Build + + CMakeProjectManager.MakeStep + + 1 + Build + + ProjectExplorer.BuildSteps.Build + + + + + + clean + + true + CMake Build + + CMakeProjectManager.MakeStep + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Minimum Size Release + Minimum Size Release + CMakeProjectManager.CMakeBuildConfiguration + + 4 + + + 0 + Deploy + + ProjectExplorer.BuildSteps.Deploy + + 1 + Deploy Configuration + + ProjectExplorer.DefaultDeployConfiguration + + 1 + + + dwarf + + cpu-cycles + + + 250 + -F + true + 4096 + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + kcachegrind + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + + Custom Executable + + ProjectExplorer.CustomExecutableRunConfiguration + + 3768 + false + true + false + false + true + + + + 1 + + + + ProjectExplorer.Project.TargetCount + 1 + + + ProjectExplorer.Project.Updater.FileVersion + 22 + + + Version + 22 + + diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..bbd5b33 --- /dev/null +++ b/LICENSE @@ -0,0 +1,14 @@ +ISC License + +Copyright (c) 2019 by Eduardo Quirós + +Permission to use, copy, modify, and /or distribute this software for any +purpose with or without fee is hereby granted, provided that the above copyright +notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD +TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. +IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL +DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, +WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING +OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. diff --git a/bin/Debug/linkedi-lists b/bin/Debug/linkedi-lists new file mode 100755 index 0000000..3bc0752 Binary files /dev/null and b/bin/Debug/linkedi-lists differ diff --git a/linkedi-lists.cbp b/linkedi-lists.cbp new file mode 100644 index 0000000..777bb11 --- /dev/null +++ b/linkedi-lists.cbp @@ -0,0 +1,41 @@ + + + + + + diff --git a/lista.cpp b/lista.cpp new file mode 100644 index 0000000..daa755b --- /dev/null +++ b/lista.cpp @@ -0,0 +1,134 @@ +#include +#include +#include "lista.h" + +using namespace std; + +Lista::Lista() +{ + head = NULL; + current = NULL; + temp = NULL; +} + +void Lista::AddNodeToEnd ( int data ) +{ + nodePtr n = new node; + n->next = NULL; + n->data = data; + + if ( head != NULL ) { //Si la lista tiene elementos, inicia el recorrido. + current = head; + + while ( current->next != NULL ) { //Si no esta al final de la lista, continua. + current = current->next; + } + current->next = n; + } else { + head = n; + } +} + +void Lista::DeleteNode ( int data ) +{ + nodePtr delPtr = NULL; + temp = head; + current = head; + + while ( current != NULL && current->data != data ) { //Siempre que hayan más nodos y la info del nodo actual no sea la buscada, entonces continúa buscando. + temp = current; + current = current->next; + } + if ( current == NULL ) { //Si se queda sin lista, no estaba el elemento. + cout << "Valor " << data << " no encontrado en la lista.\n"; + delete delPtr; + } else { + delPtr = current; + current = current->next; + temp->next = current; + delete delPtr; + cout << "Elemento borrado.\n"; + } +} + +void Lista::PrintLista() +{ + current = head; + while ( current!=NULL ) { + cout << current->data << endl; + current = current->next; + } +} + +void Lista::AddNodeToStart (int data) +{ + nodePtr n = new node; + n->next = NULL; + n->data = data; + + if (head != NULL) + { + current = head; + n->next = current; + head = n; + } + else + { + head = n; + } +} + +void Lista::DeleteNodeByPosition (int position) +{ + nodePtr delPtr = NULL; + temp = head; + current = head; + + for(int i = 0; i < position ; ++i) + { + if(current->next != NULL) + { + temp = current; + current = current->next; + + } + else + { + cout << "Esa posición no existe.\n"; + break; + } + + } + delPtr = current; + + if (current->next != NULL) + { + current = current->next; + temp->next = current; + } + else + { + temp->next = NULL; + } + + delete delPtr; +} + +void Lista::FindNode(int data) +{ + nodePtr n = new node; + temp = head; + current = head; + + while ( current != NULL && current->data != data ) { //Siempre que hayan más nodos y la info del nodo actual no sea la buscada, entonces continúa buscando. + temp = current; + current = current->next; + } + if ( current == NULL ) { //Si se queda sin lista, no estaba el elemento. + cout << "Valor " << data << " no encontrado en la lista.\n"; + } + else + { + cout << "El dato introducido fue encontrado.\n"; + } +} diff --git a/lista.h b/lista.h new file mode 100644 index 0000000..e1124c5 --- /dev/null +++ b/lista.h @@ -0,0 +1,30 @@ +#ifndef LISTA_H +#define LISTA_H + +/** + * @todo write docs + */ +class Lista +{ +private: + typedef struct node { + int data; + node* next; + }* nodePtr; + + nodePtr head; + nodePtr current; + nodePtr temp; + +public: + Lista(); + void AddNodeToEnd ( int data ); + void DeleteNode ( int data ); + void PrintLista(); + void AddNodeToStart (int data); + void DeleteNodeByPosition (int position); + int CountNodes(); + void FindNode (int data); +}; + +#endif // LISTA_H diff --git a/main b/main new file mode 100755 index 0000000..dbd8a62 Binary files /dev/null and b/main differ diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..783bc9d --- /dev/null +++ b/main.cpp @@ -0,0 +1,22 @@ +#include +#include "lista.cpp" + +using namespace std; + +int main(int argc, char **argv) { + Lista Eduardo; + Eduardo.AddNodeToEnd(1); + Eduardo.AddNodeToEnd(2); + Eduardo.AddNodeToEnd(3); + + Eduardo.DeleteNode(5); + + Eduardo.PrintLista(); + + Eduardo.AddNodeToStart(98); + Eduardo.PrintLista(); + + Eduardo.DeleteNodeByPosition(60); + Eduardo.PrintLista(); + return 0; +}