diff options
Diffstat (limited to '3.01.singlelinkedList.cc')
| -rw-r--r-- | 3.01.singlelinkedList.cc | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/3.01.singlelinkedList.cc b/3.01.singlelinkedList.cc new file mode 100644 index 0000000..73f765b --- /dev/null +++ b/3.01.singlelinkedList.cc @@ -0,0 +1,78 @@ +/* + * ===================================================================================== + * + * Filename: 3.01.singlelinkedList.cc + * + * Description: Single linked list + * + * Version: 1.0 + * Created: 23.04.2014 12:13:13 + * Revision: none + * Compiler: gcc + * + * Author: Stefan Suhren (SSuhren), suhren.stefan@fh-swf.de + * Organization: FH Südwestfalen, Iserlohn + * + * ===================================================================================== + */ + +#include <cstdlib> +#include <iostream> +#include <iomanip> + +using namespace std; + +struct Element{ + long key; // Schluessel des Listenelements + long info; // die im Listenelement zu verwaltende Information + struct Element *next; // Zeiger auf nächste Element +}; + +// === FUNCTION ====================================================================== +// Name: main +// Description: Simple program no functions needed +// ===================================================================================== +int main ( int argc, char *argv[] ){ + // Create pointer for start and search + struct Element* L = NULL, *cursor = NULL; + + // Create actual elements + struct Element x1, x2, x3, x4; + + // Initialize structs + x1.key = 1; + x1.info = 11; + x2.key = 2; + x2.info = 22; + x3.key = 3; + x3.info = 33; + x4.key = 4; + x4.info = 44; + + // Now create the linked list + L = &x1; + x1.next = &x2; + x2.next = &x3; + x3.next = &x4; + x4.next = NULL; + + // Set cursor to starting point + cursor = L; + + // Go over the List until the list ends or the key is found + while(cursor != NULL && cursor->key != 3){ + cursor = cursor->next; + } + + // Check if value was found + if(cursor != NULL){ + cout << "key = " << setw(15) << cursor->key << endl + << "info = " << setw(15) << cursor->info << endl + << "next = " << setw(15) << cursor->next << endl; + } + else{ + cout << "Value not found!!!"; + } + + return EXIT_SUCCESS; +} // ---------- end of function main ---------- |
