Last active
February 26, 2016 06:46
-
-
Save teknoman117/2316efacbccb7e059851 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include "Stack.h" | |
using namespace std; | |
int main (int argc, char **argv) | |
{ | |
int N; | |
Stack stack; | |
stack.initialize(); | |
cin >> N; | |
for(int i = 0; i < N; i++) | |
{ | |
double val; | |
cin >> val; | |
stack.push(new double(val)); | |
} | |
// Print out everything | |
Stack::Link *current = stack.head; | |
while(current != NULL) | |
{ | |
double *val = static_cast<double *>(current->data); | |
cout << *val << endl; | |
current = current->next; | |
} | |
void *datum = NULL; | |
while((datum = stack.pop()) != NULL) | |
{ | |
delete static_cast<double *>(datum); | |
} | |
stack.cleanup(); | |
return 0; | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef __LINKEDLIST__ | |
#define __LINKEDLIST__ | |
#include <iostream> | |
struct LinkedList | |
{ | |
struct Link | |
{ | |
void* data; | |
Link* next; | |
Link(void* dat, Link* nxt) | |
{ | |
data = dat; | |
next = nxt; | |
} | |
}* head; | |
LinkedList(void* dat, Link* nxt) | |
{ | |
head = new Link(dat, nxt); | |
} | |
void add(LinkedList::Link* l, int n) | |
{ | |
for(int i = n; i > 0; i--) | |
{ | |
l->next = new Link(new double(i-1), l->next); | |
} | |
} | |
void print() | |
{ | |
Link* current = head; | |
while(current != NULL) | |
{ | |
std::cout << *static_cast<double *>(current->data) << std::endl; | |
current = current->next; | |
} | |
} | |
void cleanup() | |
{ | |
Link* current = head; | |
while(current != NULL) | |
{ | |
delete static_cast<double *>(current->data); | |
Link* n = current->next; | |
delete current; | |
current = n; | |
} | |
head = NULL; | |
} | |
}; | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment