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

    链栈:

    参见:http://www.cnblogs.com/emanlee/archive/2007/09/12/890647.html

    #include<stdio.h>
    #include
    <stdlib.h>
    struct  stacknode
    {
     
    int  data;
     
    struct  stacknode *next;
     };

    //
    struct stacknode * InitialLinkList ()
    {
     
    struct stacknode * head;
     head
    =(struct stacknode *)
         malloc(
    sizeof(struct stacknode ));//
     head->next=NULL;
     
    return head;
    }

    //入栈
    void PushIntoStack(struct stacknode * head, int value)
    {
        
    struct stacknode * p;
        p
    =(struct stacknode *)malloc(sizeof(struct stacknode ));
        p
    ->data=value;
        p
    ->next=head->next;
        head
    ->next=p;
     }

     
    void PopFromStack(struct stacknode * head)
    {
     
    struct stacknode * p;
     
    if(head->next==NULL)
       printf(
    "Pop Failed \n");
     
    else
        {
            p
    =head->next;
         head
    ->next=p->next;
        free(p);
         }
    }
     
     
    void ShowStackElement(struct stacknode *head)
     {
        
    struct stacknode * p;
        p
    =head->next;
        printf(
    "\n显示栈中元素:\n");
        
    while(p!=NULL)
        {
            printf(
    " %d ",p->data);
            p
    =p->next;
        }

     }

     
    void main()
     {
       
    struct stacknode *head;
       head
    =InitialLinkList();
       PushIntoStack(head,
    1);
       ShowStackElement(head);
        PushIntoStack(head,
    2);
       ShowStackElement(head);
        PushIntoStack(head,
    3);
       ShowStackElement(head);
       PopFromStack(head);
       ShowStackElement(head);
       PopFromStack(head);
       ShowStackElement(head);
        PopFromStack(head);
       ShowStackElement(head);
        PopFromStack(head);
       ShowStackElement(head);
        PopFromStack(head);
       ShowStackElement(head);
     }
  • 相关阅读:
    centos6和centos7网卡修改
    centos7.4编译安装LNMP
    centos7yum安装LNMP
    jira搭建
    centos6.9编译安装LNMP
    监控命令命令
    linux设置命令历史的时间戳
    zabbix3.0安装
    Mysql(centos7) 主从搭建
    Android 利用剪切板(clipboardManager )实现数据传递
  • 原文地址:https://www.cnblogs.com/emanlee/p/1292303.html
Copyright © 2011-2022 走看看