Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <malloc.h>
- #include <iostream>
- template <typename T>
- class list{
- private:
- struct element{
- T data;
- struct element * next;
- };
- element * head;
- public:
- list(T elem){
- element * p = (struct element *) malloc(sizeof(struct element));
- p->data = elem;
- p->next = head;
- head = p;
- }
- };
- void main(){
- struct element * head = NULL;
- for (int i = 0; i < 50; i++){
- struct element * ml = (struct element *) malloc (sizeof(struct element));
- ml->data = i;
- ml->next = NULL;
- if (head == NULL) head = ml;
- else {
- struct element * cur = head;
- while (cur->next != NULL)
- cur = cur->next;
- cur->next = ml;
- }
- }
- list a(-1);
- struct element * cur = head;
- while (cur != NULL){
- std::cout << cur->data << " ";
- cur = cur->next;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement