fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. struct Node{
  5. int val;
  6. Node* next;
  7. Node(int val):next(nullptr),val(val){};
  8. };
  9.  
  10. Node* removefirst(Node* head){
  11. if(head == nullptr)return nullptr;
  12. if(head->next == nullptr){
  13. delete head;
  14. return nullptr;
  15. }
  16.  
  17. Node* temp = head->next;
  18. delete head;
  19.  
  20. return temp;
  21. }
  22.  
  23. Node* LL(vector<int>&a){
  24. Node* head = new Node(a[0]);
  25. Node* curr = head;
  26.  
  27. for(int i = 1;i<a.size();i++){
  28. curr->next = new Node(a[i]);
  29. curr = curr->next;
  30. }
  31. return head;
  32. }
  33. void print(Node* head){
  34. Node* temp = head;
  35.  
  36. while(temp!=nullptr){
  37. cout<<temp->val<<endl;
  38. temp = temp->next;
  39. }
  40. }
  41. int main() {
  42. int n;
  43. cin>>n;
  44.  
  45. vector<int>a(n);
  46. for(int i = 0 ;i < n ;i++){
  47. cin>>a[i];
  48. }
  49.  
  50. Node* head = LL(a);
  51. Node* temp = removefirst(head);
  52.  
  53. print(temp);
  54. return 0;
  55. }
Success #stdin #stdout 0.01s 5304KB
stdin
5
1 2 3 4  5
stdout
2
3
4
5