zoukankan      html  css  js  c++  java
  • 头插法建立单链表

    #include<stdio.h>
    #include<stdlib.h>

    typedef struct node{
    int data;
    struct node *next;
    }LNode,*LinkList;

    LinkList creat_list()
    {
    LinkList head=NULL;
    head=(LinkList)malloc(sizeof(LNode));
    if(head==NULL)
    {
    printf("memory out of use ");
    return NULL;
    }
    head->next=NULL;
    head->data=0;
    return head;
    }

    int insert(LinkList head,int n)
    {
    for(int i=0;i<n;i++)
    {

    LinkList head_t=head->next;
    LinkList new_node=NULL;


    new_node=(LinkList)malloc(sizeof(LNode));
    if(new_node==NULL)
    {
    printf("memory out of use ");
    return -1;
    }
    printf("please input the value: ");
    scanf("%d",&new_node->data);
    new_node->next=head_t;
    head->next=new_node;
    }

    return 0;
    }
    int show_list(LinkList head)
    {
    LinkList tem;
    tem=head->next;
    while(tem)
    {
    printf("%3d",tem->data);
    tem=tem->next;
    }
    return 0;
    }

    int main()
    {
    LinkList head;
    int n;
    printf("please input the size which you want to insert ");
    scanf("%d",&n);
    head=creat_list();
    insert(head,n);
    show_list(head);
    return 0;
    }

  • 相关阅读:
    Odoo电子数据交换(EDI)
    WMS8_仓库配置
    odoo写邮件添加收件人
    Odoo HR Payslip
    openERP邮件(发信、收信)
    Multi-company rules
    MRP Force Reservation的作用
    使用虚拟机VM运行Linux版OpenERP
    采购预付款
    消除递归的方法
  • 原文地址:https://www.cnblogs.com/loveyan/p/4563160.html
Copyright © 2011-2022 走看看