xxxxxxxxxx
#include <bits/stdc++.h>
using namespace std;
void display(list<int> &lst){
list<int> :: iterator it;
for(it = lst.begin(); it != lst.end(); it++){
cout<<*it<<" ";
}
}
int main(){
list<int> list1;
int data, size;
cout<<"Enter the list Size ";
cin>>size;
for(int i = 0; i<size; i++){
cout<<"Enter the element of the list ";
cin>>data;
list1.push_back(data);
}
cout<<endl;
display(list1);
return 0;
}
List in C++
xxxxxxxxxx
#include <iostream>
class Node{
public:
Node* next;
int element;
};
int main(){
Node* head = new Node();
head -> next = new Node();
head -> element = 10;
head -> next = new Node();
head -> next -> element = 11;
head -> next -> next = nullptr;
std::cout<<head->element<<std::endl;
std::cout<<head->next->element<<std::endl;
return 0;
}