zoukankan      html  css  js  c++  java
  • 链栈

     1 #include<iostream>
     2 #include<ctime>
     3 using namespace std;
     4 
     5 struct linknode
     6 {
     7     int number;
     8     linknode *next;
     9 };
    10 
    11 
    12 struct linkstack
    13 {
    14     int count;
    15     linknode *top;
    16 };
    17 
    18 
    19 
    20 
    21 void Push(linkstack *s, int e)
    22 {
    23     linknode *t = new linknode;
    24     t->number = e;
    25     t->next = s->top;
    26     s->count++;
    27     s->top = t;
    28 }
    29 
    30 
    31 int Pop(linkstack *s)
    32 {
    33     int t;
    34     if (s->count > 0)
    35     {
    36         s->count--;
    37         linknode *p = s->top;
    38         t = s->top->number;
    39         s->top = p->next;
    40         delete p;
    41     }
    42     return t;
    43 }
    44 
    45 
    46 void initstack(linkstack *s,int n)
    47 {
    48     linknode *t;
    49     srand(time(0));
    50     for (int i = 1; i <= n; i++)
    51     {
    52         t = new linknode;
    53         t->number = rand() % 100 + 1;
    54         t->next = s->top;
    55         s->top = t;
    56     }
    57     s->count += n;
    58 }
    59 
    60 
    61 void main()
    62 {
    63     linkstack *t = new linkstack;
    64     t->top = new linknode;
    65     t->top->number = rand() % 100 + 1;
    66     t->count = 0;
    67     t->top->next = NULL;
    68     initstack(t, 10);
    69     for (int i = 1; i <= 10; i++)
    70         cout << Pop(t)<<endl;
    71 }

  • 相关阅读:
    Linux ansible的group模块
    ansible copy 模块详解
    Linux centos yum仓库 自制
    ansible 的playbook脚本
    Linux centos 监控备份
    Linux centos nginx下载安装初步
    周总结5
    周总结4
    爬取
    结对开发
  • 原文地址:https://www.cnblogs.com/zhengzhe/p/6438190.html
Copyright © 2011-2022 走看看