小编Aas*_*mar的帖子

无法从链接列表中弹出顶部元素

我试图创建一个简单的链接列表程序,当我试图从列表中弹出第一个元素时,它没有弹出,它仍然是列表中的第一个元素,请帮我解决这个错误.

这是代码:

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

void create(stack *s){
 if(s == NULL){
    s = (stack*)malloc(sizeof(stack)*1);
    (s->next)=NULL;
 }
 else{
    stack *temp = (stack*)malloc(sizeof(stack)*1);
    (temp->next)=s;
    s=temp;
 }
}

void push(stack *s, char x){
   create(s);
   (s->value)=x;
}

void isEmpty(stack *s){
    if(s == NULL){
        printf("List is Empty!\n");
    }
    else{
        printf("List is not Empty!\n");
    }
}

char pop(stack *s){
 if(s == NULL){
    isEmpty(s);
    return -1;
 }
 char x=s->value;
 s=(s->next);
 return x;
}   

int main(int argc , char* argv[]){
stack *s;
create(s);
char choice,data;
printf("Stack Created\n\n"); …
Run Code Online (Sandbox Code Playgroud)

c linked-list

0
推荐指数
1
解决办法
81
查看次数

标签 统计

c ×1

linked-list ×1