#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. 初识Ajax---简单的Ajax应用实例

    原文: http://www.ido321.com/347.html 从网页前端输入提示范围内的字符,然后显示从后台返回的结果 1: <html> 2: <head> 3: & ...

  2. Android Socket 相关

    http://www.imooc.com/learn/223 http://www.epubit.com.cn/book/onlinechapter/12093

  3. English Morphology

    最近参与一个小project,需要编写一个针对英文单词的stem 算法. 1. 最为常见的stem 算法 就是The English (Porter2) stemming algorithm http ...

  4. RESTLET开发实例

    1 前提 由于近期工作的需要,要把RESTLET应用到项目中,于是在网上参考了一些资料的基础上,实践了一个关于RESTLET接口的小例子. Restlet的思想是:HTTP客户端与HTTP服务器之间的 ...

  5. HW6.12

    import java.util.Scanner; public class Solution { public static void main(String[] args) { Scanner i ...

  6. String类 and StringBuffer类

    1.equals() ==: a)对于原生数据类型来说,比较的是左右两边的值是否相等. b)对于引用类型来说,比较左右两边的引用是否指向同一个对象,或者说左右两边的引用地址是否相同. equals() ...

  7. leetcode@ [131/132] Palindrome Partitioning & Palindrome Partitioning II

    https://leetcode.com/problems/palindrome-partitioning/ Given a string s, partition s such that every ...

  8. kvm guest usb mapping

    http://www.linux-kvm.org/page/USB#Input_devices http://www.linux-kvm.org/page/USB_Host_Device_Assign ...

  9. SQL Where语句中AND与OR的计算次序 .

    AND 用在where子句中,用来指示检索满足所有给定条件的行,而OR用在where子句中,用来指示检索匹配任一给定条件的行. Where子句中可包含任意数目的AND和OR操作符号,但是要注意在SQL ...

  10. emWin -- 模拟器系列1 - 如何建立模拟器开发环境

    面对如此强大的emWin,大家是否都有跃跃欲试的冲动呢?但是没有硬件可以调试的童鞋,难道只能望洋兴叹?非也.非也.Segger公司早就考虑到了.Segger推出模拟器的目的不仅仅是为了解决没有硬件的烦 ...