Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <ctime>
- using namespace std;
- struct node{
- int val;
- node* next;
- };
- void add(node *&test, int a ){
- node* temp = new node;
- temp->val =a;
- temp->next = NULL;
- if(test==NULL){
- test=temp;
- }else{
- node* t = test;
- while(t->next!=NULL){
- t=t->next;
- }
- t->next = temp;
- }
- }
- int main(){
- srand (time(NULL));
- node* a;
- a = NULL;
- add(a, 10);
- for(int i = 0; i<10; i++){
- add(a, rand()%50);
- }
- while(a->next!=NULL){
- cout<<a->val<<endl;
- a=a->next;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement