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); }
hackerrank Day15: Linked List的更多相关文章
- [LeetCode] Linked List Random Node 链表随机节点
		
Given a singly linked list, return a random node's value from the linked list. Each node must have t ...
 - [LeetCode] Plus One Linked List 链表加一运算
		
Given a non-negative number represented as a singly linked list of digits, plus one to the number. T ...
 - [LeetCode] Odd Even Linked List 奇偶链表
		
Given a singly linked list, group all odd nodes together followed by the even nodes. Please note her ...
 - [LeetCode] Delete Node in a Linked List 删除链表的节点
		
Write a function to delete a node (except the tail) in a singly linked list, given only access to th ...
 - [LeetCode] Palindrome Linked List 回文链表
		
Given a singly linked list, determine if it is a palindrome. Follow up: Could you do it in O(n) time ...
 - [LeetCode] Reverse Linked List 倒置链表
		
Reverse a singly linked list. click to show more hints. Hint: A linked list can be reversed either i ...
 - [LeetCode] Remove Linked List Elements 移除链表元素
		
Remove all elements from a linked list of integers that have value val. Example Given: 1 --> 2 -- ...
 - [LeetCode] Intersection of Two Linked Lists  求两个链表的交点
		
Write a program to find the node at which the intersection of two singly linked lists begins. For ex ...
 - [LeetCode] Linked List Cycle II 单链表中的环之二
		
Given a linked list, return the node where the cycle begins. If there is no cycle, return null. Foll ...
 
随机推荐
- 【译】 AWK教程指南 附录D-AWK的内置变量
			
因内置变量的个数不多,此处按其相关性分类说明,并未按其字母顺序排列. ARGC ARGC表示命令行上除了选项 -F, -v, -f 及其所对应的参数之外的所有参数的个数.若将"awk程序&q ...
 - 【noip2007】树网的核
			
题解: 首先我们要知道一个性质:如果有多条直径 这个核不论在哪条直径上 答案都是一样的 这样我们就可以随便找一条直径 在这条直径上枚举核的位置 并且dfs预处理maxlon[i] (i在直径上) 表示 ...
 - android界面优化笔记(TODO)
			
1.避免使用线性布局的层层嵌套,要使用相对而已.使用线性布局越多,嵌套越多 官方文档: Optimizing Your UI
 - Redis实战之征服 Redis + Jedis + Spring (一)
			
Redis + Jedis + Spring (一)—— 配置&常规操作(GET SET DEL)接着需要快速的调研下基于Spring框架下的Redis操作. 相关链接: Redis实战 Re ...
 - Postfix上的反垃圾邮件的四个方法
			
在介绍如何配置Postfix的smtp配置之前有必要首先介绍一下它的背景和特点.Postfix是一个由IBM资助下由WietseVenema 负责开发的自由软件工程的一个产物,其目的是为用户提供除se ...
 - 【09】绝不在构造和析构过程中调用virtual方法
			
1.绝不在构造和析构过程中调用virtual方法,为啥? 原因很简单,对于前者,这种情况下,子类专有成分还没有构造,对于后者,子类专有成分已经销毁,因此调用的并不是子类重写的方法,这不是程序员所期望的 ...
 - leetcode第一刷_Jump Game
			
这个题事实上非常easy的,我一開始想复杂了,它没要求记录路径,事实上仅仅要看一下每一步之后所能延伸到的最远的位置就能够了,在这一个最远位置前面的那些位置,都是能够到达的,假设扫到了某个i,它大于当前 ...
 - 金蝶KIS 13.0专业版破解方法破解安装流程 金蝶KIS 13.0专业版安装流程
			
金蝶KIS 13.0安装 1.先安装操作系统Windows server 2008 R2. 2.再安装SQL2008 R2. 3.再安装金蝶KIS 13.0专业版. 在安装时记住须要将系列号设置成为1 ...
 - Git链接到自己的Github(1)简单的开始
			
好长时间没上来弄东西了,今天回来先开始弄下Git,之后再继续写uboot与kernel的编译,在版本控制下更加宏观地观察每次的变化. 1.在ubuntu中安装git $ sudo apt-get in ...
 - 转--23种设计模式的搞笑解释(后续放逐一C++解释版本)
			
创建型模式 1.FACTORY —追MM少不了请吃饭了,麦当劳的鸡翅和肯德基的鸡翅都是MM爱吃的东西,虽然口味有所不同,但不管你带MM去麦当劳或肯德基,只管向服务员说“来四个鸡翅”就行了.麦当劳和肯德 ...