hackerrank Day15: Linked List

 #include <iostream>
#include <cstddef>
using namespace std;
class Node
{
public:
int data;
Node *next;
Node(int d){
data=d;
next=NULL;
}
};
class Solution{
public:
Node* insert(Node *head,int data)
{
Node *temp = new Node(data);
if(head == NULL){
head = temp;
return head;
}
Node *q, *p;
p = head;
q = head -> next; while(q){
p = q;
q = p -> next;
} p -> next = temp;
return head;
}
void display(Node *head)
{
Node *start=head;
while(start)
{
cout<<start->data<<" ";
start=start->next;
}
}
};
int main()
{
Node* head=NULL;
Solution mylist;
int T,data;
cin>>T;
while(T-->){
cin>>data;
head=mylist.insert(head,data);
}
mylist.display(head); }
上一篇:javascript – coinmarketcap api v2 jquery


下一篇:为什么这个来自python的bash调用不起作用?