#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的更多相关文章

  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. Magento 头部的演示信息去除

    进入后台: 系统-配置, 然后选择左栏的“设计”, 选择右栏的HTML头信息里面有个“Display Demo Store Notice”, 默认是yes,设置为“no”就可以了.

  2. jsp:forward与缓冲区

    jsp:forward的作用是在服务器端进行页面跳转.通常有<jsp:forward page="NewPage.jsp">语句的页面的在执行时会提前执行跳转,而不输出 ...

  3. leetcode—Palindrome 解题报告

    1.题目描述 Given a string s, partition s such that every substring of the partition is a palindrome. Ret ...

  4. 解决outlook无法启动

    当outlook出现上述问题时,修复的方案: 1.在打开的命令提示符窗口中,输入"cd C:\Program Files\Microsoft Office\Office12"然后回 ...

  5. HDFS的shell操作

    bin/hadoop命令操作: namenode -format 格式化文件系统 fs(缩写:FileSystem) 运行一个文件系统的用户客户端 bin/hadoop fs常用命令操作: -ls h ...

  6. leetcode@ [300] Longest Increasing Subsequence (记忆化搜索)

    https://leetcode.com/problems/longest-increasing-subsequence/ Given an unsorted array of integers, f ...

  7. Codeforces Round #225 (Div. 2)

    比赛时候只做出AB,E题一眼看过去似乎线段树能搞,但是写完过不了样例,才发现看错题了,然后比赛就没啥时间了~~整体状况还是很糟糕,A,B题实在出得太慢,然后持续到现在还没出过C题...不能更弱%> ...

  8. ffmpeg 的tutorial

    可能是新的: https://github.com/chelyaev/ffmpeg-tutorial https://github.com/chelyaev/ffmpeg-tutorial.git 老 ...

  9. 转载ASP.NET MVC 中@Html.Partial,@Html.Action,@Html.RenderPartial,@Html.RenderAction区别

    对这四个的区别做一个总结,清理一下思路,方便以后使用: 1.带有Render的方法返回值是void,在方法内部进行输出:不带的返回值类型为MvcHtmlString,所以只能这样使用:     @Ht ...

  10. Oracle- 存储过程和异常捕捉

    这段时间晚上有时候去打打球,回家看看电视剧,日子一天天过…….学了点ORACLE存储过程基础,作一下备注,以便日后需查阅. 创建无参存储过程 create procedure p_myPro1 is ...