Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- struct Node{
- int data;
- struct Node *link;
- };
- struct Node*ptr;
- void push(int data){
- struct Node*temp;
- temp=new Node();
- temp->data=data;
- temp->link=ptr;
- ptr=temp;
- }
- void display()
- {
- struct Node* temp;
- if(ptr!=NULL) {
- temp = ptr;
- while (temp != NULL) {
- // print node data
- cout << temp->data << " ";
- // assign temp link to temp
- temp = temp->link;
- }
- }
- }
- int main(){
- push(11);
- push(22);
- push(50);
- push(60);
- push(70);
- display();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement