zoukankan      html  css  js  c++  java
  • 2008秋季计算机软件基础0908课堂用例(2)

    #include<stdio.h>
    #include
    <stdlib.h>
    struct nodetype
    {
        
    int data;
        
    /* data数据项用于存放结点的数据值 */
        
    struct nodetype *next; 
        
    /* next数据项存放下一个结点的指针 */
    };
    struct nodetype * InitialLinkList ()
    {
     
    struct nodetype * head;
     head
    =(struct nodetype *)malloc(sizeof(struct nodetype ));//
     head->next=NULL;
     
    return head;
    }

    void CreateLinkListInRear(struct nodetype * head, int a[], int n)
    {   
    int i;  struct nodetype * temp,* rear;
        rear
    =head;
        
    for(i=0;i<n;i++)
        {
            temp
    =(struct nodetype *)malloc(sizeof(struct nodetype));
            temp
    ->data=a[i];
            temp
    ->next=NULL;
            rear
    ->next=temp;
        rear
    =temp;
        }
    }

    void CreateLinkListInHead(struct nodetype * head,
                              
    int a[], int n)
    {   
    int i;struct nodetype * temp,*front;
        
    for(i=0;i<n;i++)
        {
            temp
    =(struct nodetype *)malloc(
                
    sizeof(struct nodetype));
            temp
    ->data=a[i];
            temp
    ->next=head->next;
            head
    ->next=temp;
        }
    }

    void printlinklist(struct nodetype * head)
    {
      
    struct nodetype * p;
      p
    =head->next;
      
    while(p!=NULL)
      {
        printf(
    " %d ",p->data);
        p
    =p->next;
      }
    }

    void main()
    {
      
    struct nodetype * head;
      
    int a[3]={3,2,1};
      head
    =InitialLinkList();
      
    //CreateLinkListInRear(head,a,3);
      CreateLinkListInHead(head,a,3);
      printlinklist(head);
    }

    参看: http://www.cnblogs.com/emanlee/archive/2007/09/10/888942.html

  • 相关阅读:
    自动化系列-pyppeteer安装
    用python做一个可视化生成二维码的工具
    Python第三方包之DingDingBot
    封装属于自己的Python包
    sqlldr使用
    MS MQ 消息队列
    PDF打印
    oracle 存储过程编辑 卡死
    winrar 压缩文件方法
    数值 转换 成 带千位符的数值,且转成大写
  • 原文地址:https://www.cnblogs.com/emanlee/p/1286903.html
Copyright © 2011-2022 走看看