aboutsummaryrefslogtreecommitdiffstats
path: root/LinkedLists.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'LinkedLists.cpp')
-rw-r--r--LinkedLists.cpp41
1 files changed, 41 insertions, 0 deletions
diff --git a/LinkedLists.cpp b/LinkedLists.cpp
new file mode 100644
index 0000000..55dc090
--- /dev/null
+++ b/LinkedLists.cpp
@@ -0,0 +1,41 @@
+#include <iostream>
+
+using namespace std;
+
+struct intList {
+ int val;
+ intList* next_el;
+};
+
+// add functions to add elements to a list
+// create a list and be able to order them
+// make ordered linked list
+
+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;
+}