Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class List{
- public:
- List(){ next = NULL; data = 0;}
- int data;
- List* next;
- };
- void output (List* root){
- List node = new List();
- while(root != NULL){
- cout << root->data << " ";
- root = root->next;
- }
- cout << endl;
- }
- void push (List*& root, int value){ // insert line to the end ||-||-|new|
- List *node = new List();
- node->data = value;
- node->next = root;
- root = node;
- //output(root);
- //delete node;
- }
- int main(){
- List* root = new List();
- push(root, 10);
- cout << root->data;
- push(root, 20);
- cout << root->data << " ";
- output(root);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement