hackerrank Day15: Linked List
2024-10-15 10:16:06
#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); }
最新文章
- 【分布式】Zookeeper的Leader选举
- Java三大框架之——Hibernate
- c++共享内存(转载)
- ThroughRain第一次冲刺总结
- Windows下MongoDB安装与设置
- java 14 -7 Date
- 二叉树建立,先序、中序、后序遍历(c实现)
- Apache Thrift - 可伸缩的跨语言服务开发框架
- vi/vim使用指北 ---- Sample Editing
- VC++6.0连接Access数据库
- awk里的各种坑
- commons-pool2-中的一些配置
- 使用 CXF 做 webservice 简单例子[转]
- 算法笔记_015:快速排序(Java)
- postman 第3节 API请求和查看响应结果(转)
- WebForm+一般处理程序+Ajax聊天
- Java 消除过期的对象引用
- 消息对话框 MessageBoxButtons
- 学习STM32,你不得不了解的五大嵌入式操作系统
- WPF模拟探照灯文字