1. #include <iostream>
  2. #include <cstddef>
  3. using namespace std;
  4. class Node
  5. {
  6. public:
  7. int data;
  8. Node *next;
  9. Node(int d){
  10. data=d;
  11. next=NULL;
  12. }
  13. };
  14. class Solution{
  15. public:
  16. Node* insert(Node *head,int data)
  17. {
  18. Node *temp = new Node(data);
  19. if(head == NULL){
  20. head = temp;
  21. return head;
  22. }
  23. Node *q, *p;
  24. p = head;
  25. q = head -> next;
  26.  
  27. while(q){
  28. p = q;
  29. q = p -> next;
  30. }
  31.  
  32. p -> next = temp;
  33. return head;
  34. }
  35. void display(Node *head)
  36. {
  37. Node *start=head;
  38. while(start)
  39. {
  40. cout<<start->data<<" ";
  41. start=start->next;
  42. }
  43. }
  44. };
  45. int main()
  46. {
  47. Node* head=NULL;
  48. Solution mylist;
  49. int T,data;
  50. cin>>T;
  51. while(T-->){
  52. cin>>data;
  53. head=mylist.insert(head,data);
  54. }
  55. mylist.display(head);
  56.  
  57. }

hackerrank Day15: Linked List的更多相关文章

  1. [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 ...

  2. [LeetCode] Plus One Linked List 链表加一运算

    Given a non-negative number represented as a singly linked list of digits, plus one to the number. T ...

  3. [LeetCode] Odd Even Linked List 奇偶链表

    Given a singly linked list, group all odd nodes together followed by the even nodes. Please note her ...

  4. [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 ...

  5. [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 ...

  6. [LeetCode] Reverse Linked List 倒置链表

    Reverse a singly linked list. click to show more hints. Hint: A linked list can be reversed either i ...

  7. [LeetCode] Remove Linked List Elements 移除链表元素

    Remove all elements from a linked list of integers that have value val. Example Given: 1 --> 2 -- ...

  8. [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 ...

  9. [LeetCode] Linked List Cycle II 单链表中的环之二

    Given a linked list, return the node where the cycle begins. If there is no cycle, return null. Foll ...

随机推荐

  1. 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 ...

  2. windows环境下mysql忘记密码如何重置

    本文主要是针对mysql重置密码过程中出现“mysqld不是内部命令或外部命令”的问题而写的.网上有很多关于mysql忘记密码了如何找回的文章,但是很多说的都不够详细,特别是还要用到DOS命令,可能这 ...

  3. 转载 asp.net中ViewState的用法详解

    转载原地址: http://www.jb51.net/article/73662.htm 在web窗体控件设置为runat = "server",这个控件会被附加一个隐藏的属性_V ...

  4. C#模仿360安全卫士玻璃按钮,不闪烁,背景切换效率快

    首先先上效果图: 1.准备两张透明的png图片(尺寸74 x 82),一张用于鼠标进入控件时显示,一张用于鼠标单击控件时显示 2.拖一个GlassButton按钮 3.设置按钮属性 this.btnE ...

  5. NoInstall_Mysql

    安装卸载一直是mysql比较头疼的问题,前几天得知可以用绿色版的mysql,解决了这一难题.

  6. MyBatis如何防止SQL注入

    转自:http://www.myexception.cn/sql/1938757.html SQL注入是一种代码注入技术,用于攻击数据驱动的应用,恶意的SQL语句被插入到执行的实体字段中(例如,为了转 ...

  7. byte数组和int互转

    import java.nio.ByteBuffer; public class Program { public static void main(String[] args) { ByteBuff ...

  8. jquery 延迟加载代码

    <!--引入以下两个js文件--> <script type="text/javascript" src="./js/jquery.min.js&quo ...

  9. HP LoadRunner 11 破解及license

    国内私募机构九鼎控股打造APP,来就送 20元现金领取地址:http://jdb.jiudingcapital.com/phone.html内部邀请码:C8E245J (不写邀请码,没有现金送)国内私 ...

  10. cocos2d-x Animation

    转自:http://codingnow.cn/cocos2d-x/810.html 这一篇来学习怎么使用cocos2d-x引擎播放帧动画,就是把一帧一帧的图片像电影那样显示出来.1. 首先来了解一下相 ...