Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- class node {
- public:
- int data;
- node* next;
- node(int data)
- {
- this->data = data;
- next = NULL;
- }
- };
- node* takeinput(node* &head)
- {
- int data; cin >> data;
- node* temp = NULL;
- while (data != -1)
- {
- node* n1 = new node(data); //dynamic
- if (head == NULL)
- {
- head = n1;
- temp = n1;
- }
- else
- {
- temp->next = n1;
- temp = n1;
- // node* temp = head;
- // while (temp != NULL)
- // {
- // temp = temp->next;
- // }
- // temp = n1;
- // while (temp->next != NULL)
- // {
- // temp = temp->next;
- // }
- // temp->next = n1;
- }
- cin >> data;
- }
- while (head != NULL)
- {
- cout << head->data << " ";
- head = (head->next);
- }
- return head;
- }
- void printlist(node* head)
- {
- // node* temp = head;
- while (head != NULL)
- {
- cout << head->data << " ";
- head = (head->next);
- }
- }
- void fun(node* n1)
- {
- n1->data = 100;
- }
- int main()
- {
- node* head = NULL;
- head = takeinput(head);
- // printlist(head);
- // node* n1 = new node(10);
- // fun(n1);
- // // node n2(100);//static
- // cout << n1->data << endl;
- // // cout << n2.data << endl;
- //static
- // node n1(10), n2(20), n3(30), n4(40), n5(50);
- // // cout << n1.data << endl;
- // // cout << n2.data << endl;
- // // cout << endl;
- // //linking process
- // node* head = &n1;
- // n1.next = &n2;
- // n2.next = &n3;
- // n3.next = &n4;
- // n4.next = &n5;
- //print the values of list
- // while (head != NULL)
- // {
- // //currently i am at head
- // cout << (head->data) << endl;
- // head = (head->next);
- // }
- //dynamic process
- // node *n1 = new node(10);
- // node *n2 = new node(20);
- // cout << (n1->data) << endl;
- // cout << (n2->data) << endl;
- // //linking
- // cout << endl;
- // n1->next = n2;
- // cout << (n1->next->data) << endl;
- // node* head = takeinput();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement