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 ...
随机推荐
- leetcode@ [315/215] Count of Smaller Numbers After Self / Kth Largest Element in an Array (BST)
https://leetcode.com/problems/count-of-smaller-numbers-after-self/ You are given an integer array nu ...
- windows环境下mysql忘记密码如何重置
本文主要是针对mysql重置密码过程中出现“mysqld不是内部命令或外部命令”的问题而写的.网上有很多关于mysql忘记密码了如何找回的文章,但是很多说的都不够详细,特别是还要用到DOS命令,可能这 ...
- 转载 asp.net中ViewState的用法详解
转载原地址: http://www.jb51.net/article/73662.htm 在web窗体控件设置为runat = "server",这个控件会被附加一个隐藏的属性_V ...
- C#模仿360安全卫士玻璃按钮,不闪烁,背景切换效率快
首先先上效果图: 1.准备两张透明的png图片(尺寸74 x 82),一张用于鼠标进入控件时显示,一张用于鼠标单击控件时显示 2.拖一个GlassButton按钮 3.设置按钮属性 this.btnE ...
- NoInstall_Mysql
安装卸载一直是mysql比较头疼的问题,前几天得知可以用绿色版的mysql,解决了这一难题.
- MyBatis如何防止SQL注入
转自:http://www.myexception.cn/sql/1938757.html SQL注入是一种代码注入技术,用于攻击数据驱动的应用,恶意的SQL语句被插入到执行的实体字段中(例如,为了转 ...
- byte数组和int互转
import java.nio.ByteBuffer; public class Program { public static void main(String[] args) { ByteBuff ...
- jquery 延迟加载代码
<!--引入以下两个js文件--> <script type="text/javascript" src="./js/jquery.min.js&quo ...
- HP LoadRunner 11 破解及license
国内私募机构九鼎控股打造APP,来就送 20元现金领取地址:http://jdb.jiudingcapital.com/phone.html内部邀请码:C8E245J (不写邀请码,没有现金送)国内私 ...
- cocos2d-x Animation
转自:http://codingnow.cn/cocos2d-x/810.html 这一篇来学习怎么使用cocos2d-x引擎播放帧动画,就是把一帧一帧的图片像电影那样显示出来.1. 首先来了解一下相 ...