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

  • 相关阅读:
    [转]C#正则表达式小结
    Silverlight 参考:KeyEventArgs.Handled 属性
    一步一步搭建免费的Silverlight 2开发环境(转载)
    Silverlight2 跨域调用Web服务的方法
    BinaryFormatter 类
    从说事到流程的理解
    比尔盖茨给青少年的11条准则
    燃烧热情
    GOF模式之乱记一通
    学而不思则罔,思而不学则殆
  • 原文地址:https://www.cnblogs.com/emanlee/p/1286903.html
Copyright © 2011-2022 走看看