diff options
author | zedarider <ymherklotz@gmail.com> | 2016-02-18 11:37:45 +0000 |
---|---|---|
committer | zedarider <ymherklotz@gmail.com> | 2016-02-18 11:37:45 +0000 |
commit | af98ee7ff28cff97f5f29a5d9e65f9153531b0ee (patch) | |
tree | 86bfc53a0bc04512ac2936ee067a2b43e901e688 /LinkedLists.cpp | |
download | imperial_2015-af98ee7ff28cff97f5f29a5d9e65f9153531b0ee.tar.gz imperial_2015-af98ee7ff28cff97f5f29a5d9e65f9153531b0ee.zip |
Imperial C++ Directory
These are all the projects I’ve been working on at university.
Diffstat (limited to 'LinkedLists.cpp')
-rw-r--r-- | LinkedLists.cpp | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/LinkedLists.cpp b/LinkedLists.cpp new file mode 100644 index 0000000..2966f76 --- /dev/null +++ b/LinkedLists.cpp @@ -0,0 +1,37 @@ +#include <iostream> + +using namespace std; + +struct intList { + int val; + intList* next_el; +}; + +int main() { + intList* ilist = NULL; + int el, n; + + cout << "How many elements do you want to add to the list?" << endl; + cin >> n; + cout << "Now please enter the " << n << " integers: " << endl; + for(int i = 0; i < n; ++i) { + cin >> el; + intList* tmp = new intList; + tmp->val = el; + tmp->next_el = ilist; + ilist = tmp; + } + cout << endl; + intList* lit = ilist; + while(lit != NULL) { + cout << lit->val << endl; + lit = lit->next_el; + } + + while(ilist != NULL) { + intList* tmpilist = ilist->next_el; + delete ilist; + ilist = tmpilist; + } + return 0; +} |