zoukankan      html  css  js  c++  java
  • C语言中链表和栈

    创建了一个C语言链表和栈。包含输入数据在链表中,保存在栈里,再从栈里读取出来。

    #include <stdio.h>
    #include <string.h>

    #define MAX 1000

    typedef struct node{

    int value;
    struct node *next;
    }Node,*pNode;

    typedef struct Stacks{
    int top;
    int value[MAX]
    }stack;
    stack s;
    void CreatStack(){
    s.top = -1;
    }
    void Push(int values){
    s.value[++s.top] = values;
    }
    int Pop(){
    return s.value[s.top--];
    }
    int main()
    {

    pNode head = NULL;
    head = (pNode)malloc(sizeof(Node));
    pNode tail = head;
    tail->next = NULL;
    int i ;
    CreatStack();
    for(i = 0 ; i < 5; i++){

    pNode nodes = (pNode)malloc(sizeof(Node));
    nodes->value = i ;
    nodes->next = tail->next;
    tail->next = nodes;
    }

    pNode nodes2 = (pNode)malloc(sizeof(Node));
    nodes2 = head->next;
    for(i = 0 ; i< 5 ; i++){
    printf("%d",nodes2->value);
    Push(nodes2->value);
    nodes2 = nodes2->next;
    printf(" ");
    }

    printf(" ");
    for(i = 0 ; i < 5; i++){
    printf("%d",Pop());
    }


    return 0;
    }

  • 相关阅读:
    RabbitMQ
    RabbitMQ
    RabbitMQ
    RabbitMQ
    RabbitMQ
    RabbitMQ
    RabbitMQ
    .net 5.0
    redis
    分布式同步服务中间件
  • 原文地址:https://www.cnblogs.com/CloudStrife/p/7211109.html
Copyright © 2011-2022 走看看