#include <iostream>
#include <cstdio>
#include <stdlib.h>
using namespace std; struct list
{
int data;
list *next;
}list1; list *initlist(int num)
{//定义一个新节点
list *node=(list*)malloc(sizeof(list));
node->data=num;
node->next=NULL;
return node;
} void pushback(list **pplist,int num)
{
if(*pplist==NULL)
*pplist=initlist(num);
else if((*pplist)->next==NULL)
(*pplist)->next=initlist(num);
else
{
list *tail=*pplist;
while(tail->next)
{
tail=tail->next;//通过依次指向找到next为空的尾结点
}
tail->next=initlist(num);//在最后添加一个结点
}
} void print(list *x)
{
if(x==NULL)
{
cout<<"->NULL"<<endl;
return;
}
cout<<"->"<<x->data;
x=x->next;
print(x);
} int main(int argc, const char * argv[])
{
freopen("1.in","r",stdin);
list *l=NULL;
int t;
while(cin>>t)
{
pushback(&l, t);
}
print(l);
return ;
}

C++练习 | 创建并正序输出不带头结点的链表的更多相关文章

  1. C++练习 | 创建并倒序输出不带头结点的链表

    #include <iostream> #include <cstdio> #include <stdlib.h> #include <stack> u ...

  2. c - 逆序/正序输出每位.

    #include <stdio.h> #include <math.h> /* 判断一个正整数的位数,并按正序,逆序输出他们的位. */ int invert(int); vo ...

  3. C语言-正序输出一个一个多位数

    //正序输出一个多位数,所有的数字中间用空格分隔 int main() { ;//是可变化的 ; int d; int t =x; //先计算x的位数 ){ t /= ; mask *=; } pri ...

  4. (C++)读取一个输入的int型十进制数字的位数,并正序输出每个位上的值(不同数位的值用1个空格字符间隔)

    1 /* 2 程序功能:读取一个输入的int型十进制数字的位数,并正序输出每个位上的值(不同数位的值用1个空格字符间隔). 3 例如:当输入985这个数字时,显示如下信息: 4 985是一个3位数字! ...

  5. 二叉排序树的创建删除中序输出&&平衡树

    #include<iostream> #include<cstdio> #include<cstring> #include<cmath> #inclu ...

  6. .Net基础篇_学习笔记_第六天_for循环语法_正序输出和倒序输出

    for TAB  和 forr TAB using System; using System.Collections.Generic; using System.Linq; using System. ...

  7. sql如何查询数据库最后10条记录并正序输出

    select * from (select * from 表名 order by 字段 desc limit 10) 临时表 order by 字段

  8. 对于一棵二叉树,请设计一个算法,创建含有某一深度上所有结点的链表。 给定二叉树的根结点指针TreeNode* root,以及链表上结点的深度,请返回一个链表ListNode,代表该深度上所有结点的值,请按树上从左往右的顺序链接,保证深度不超过树的高度,树上结点的值为非负整数且不超过100000。

    /* struct TreeNode { int val; struct TreeNode *left; struct TreeNode *right; TreeNode(int x) : val(x ...

  9. java面试题:已知一个数组[2,4,6,2,1,5],将该数组进行排序(降序,不能用工具类进行排序),创建两条线程交替输出排序后的数组,线程名自定义

    package com.swift; import java.util.Arrays; import java.util.Comparator; public class ArrayThread_Te ...

随机推荐

  1. Python-MRO和C3算法

    一. python多继承 在前面的学习过程中,我们已经知道了python中类与类之间可以有继承关系,当出现x是一种y的时候就可以使用继承关系.即'is-a'关系,在继承关系中子类自动拥有父类中除了私有 ...

  2. <Android 应用 之路> 百度地图API使用(1)

    简介 详情请看百度地图官方网站 http://lbsyun.baidu.com/index.php?title=androidsdk/guide/introduction 使用方式 申请密钥,针对移动 ...

  3. arcMap 进度条

    private void kk() { IProgressDialogFactory progressDialogFactory = new ProgressDialogFactoryClass(); ...

  4. _itoa atoi、atof、itoa、itow _itoa_s 类型转换使用说明

    原文:http://www.cnblogs.com/lidabo/archive/2012/07/10/2584706.html _itoa 功能:把一整数转换为字符串 用法:char * _itoa ...

  5. linux常用命令(50个)

    1. find 基本语法参数如下: find [PATH] [option] [action] # 与时间有关的参数: -mtime n : n为数字,意思为在n天之前的“一天内”被更改过的文件: - ...

  6. 代码分析工具推荐Understand

    之前看ogitor ,第一次看到那么多代码~~不知道从哪里下手,而且好多东西都不会Ogre什么的都不是很清楚,对ogitor的代码结构的了解就更不用提了.晕头转向的 不知道从哪里下手,一点点的看起来好 ...

  7. 删除datatable的行后,出现“不能通过已删除的行访问该行的信息”的错误,即DeletedRowInaccessibleException

    删除datatable的行后,出现“不能通过已删除的行访问该行的信息”的错误 =========================================================== 采 ...

  8. plus.webview.create mui.openWindow区别是什么呢

      create 只是创建这个webview,但是不显示,而且同一个页面.同一个id你甚至能重复创建多个(严重消耗性能,作死...),其实mui里面已经封装了这个方法 mui.preload(),并且 ...

  9. 基于SAP Kyma的订单编排增强介绍

    尽管有一万个舍不得,2018年还是无可挽回地离我们远去了. 唯有SAP成都研究院的同事和我去年在网络上留下的这些痕迹,能证明2018年我们曾经很认真地去度过每一天: SAP成都研究院2018年总共87 ...

  10. mongodb启动和关闭

    mongodb的启动 mongod --dbpath=/data/mongodb/data --logpath=/data/mongodb/log/33988.log --port 33988 --f ...