Untitled
unknown
plain_text
2 months ago
1.1 kB
1
Indexable
#include<bits/stdc++.h> using namespace std ; class node{ public : int m ; int n ; node* next ; node(int m, int n ){ this->m = m ; this-> n = n ; this-> next = NULL ; } }; void print_linlist (node* &head){ node* tmp = head ; while (tmp != NULL){ cout << tmp->m << " " << tmp->n << "->" ; tmp = tmp->next ; } } void input_node(node* &head, node* &tail, int m, int n){ node* newnode = new node(m,n); if(head == NULL){ head = newnode ; tail = newnode ; return ; } tail->next = newnode ; tail= tail->next ; } int main (){ node* head = NULL ; node* tail = NULL ; int m, n ; while(true){ cin >> m >> n ; if(n == -1 || m== -1){ break ; } input_node(head, tail, m,n); } print_linlist(head); }
Editor is loading...
Leave a Comment