代码编织梦想

#include <stdio.h>
#include <stdlib.h>

typedef struct Node
{
    /* data */
    int data;
    struct Node* next;

} Node;

Node* initStack();

void push(Node* statck, int value);
int pop(Node* statck);

length(Node* list);
void printList(Node* list);

int main(int argc, char const* argv[]) {
	Node* statck = initStack();
	push(statck, 10);
	push(statck, 11);
	push(statck, 12);
	push(statck, 13);
	push(statck, 14);
	printList(statck);
	int poped = pop(statck);
	printList(statck);
	printf("pop数据 = %d\n", poped);
	int poped2 = pop(statck);
	printList(statck);
	printf("pop数据 = %d\n", poped2);
	int poped3 = pop(statck);
	printList(statck);
	printf("pop数据 = %d\n", poped3);
	return 0;
}

Node* initStack() {
	Node* statck = (Node*)malloc(sizeof(Node));
	statck->data = 0;
	statck->next = NULL;
	return statck;
}

void push(Node* statck, int value) {
	Node* node = (Node*)malloc(sizeof(Node));
	node->data = value;
	node->next = statck->next;
	statck->next = node;
	statck->data++;
}

int pop(Node* statck) {
	Node* node = statck->next;
	
	statck->data--;
	statck->next = statck->next->next;
	return node->data;
}

// 工具方法
int length(Node* list) {
    return list->data;
}

void printList(Node* list) {
    if (list->data == 0)
    {
        printf("List is empty");
        return;
    }
    list = list->next;
    printf("[ ");
    
    while (list->next)
    {
        printf("%d,", list->data);
        list = list->next;
    }
    printf("%d", list->data);
    printf(" ]\n");
}

自己备份一下

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/qq_43096296/article/details/131026892

什么是c语言?-爱代码爱编程

C语言是一种高级编程语言,于1972年由Dennis Ritchie在贝尔实验室开发出来。它是一种通用的、结构化的编程语言,被广泛用于系统软件、嵌入式系统、游戏开发以及科学计算等领域。 C语言的设计目标是提供一种简洁、高效、可移植的编程语言,以便于开发底层的系统软件。它具有强大的表达能力和灵活性,同时也提供了对计算机底层操作的直接支持。 C语言的特点之

android系统原理性问题分析 -爱代码爱编程

声明 在Android系统中经常会遇到一些系统原理性的问题,在此专栏中集中来讨论下。Android系统中很多地方都采用了I/O多路复用的机制,为了引出I/O多路复用机制,先来分析多路并发情况下的C/S模型。此篇参考一些博客