#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
struct stackNode
{
int data;
struct stackNode *nextPtr;
};
void instructions()
{
printf("[1]Push a value on the stack\n");
printf("[2]Pop a value off the stack\n");
printf("[3]Display the whole stack\n");
printf("[4]Exit");
}
void push(struct stackPtr *topPtr, int info)
{
struct stackPtr *newPtr;
newPtr= malloc(sizeof(struct stackNode));
if(newPtr !=NULL)
{
newPtr->data = info;
newPtr->nextPtr=*topPtr;
*topPtr=newPtr;
}
else
{
printf("%d not inserted no memory available");
}
int main()
{
struct StackNodePtr *stackPtr;
stackPtr = NULL;
int choice, value;
do
{
instructions();
printf("\nEnter Your Choice: ");
scanf("%d",&choice);
if(choice == 1)
{
printf("Enter a value for the stack");
}
if(choice == 2)
{
printf(" ");
}
if(choice == 3)
{
printf(" ");
}
if(choice == 4)
{
printf("bye!");
return 0;
}
} while(choice !=4);
system("pause");
}
我做了一個函數推送我的鏈表和堆棧代碼,但事情是它不工作有很大的錯誤,在功能推它有什麼問題嗎?它不允許使用malloc爲什麼?鏈接列表推送功能
OMG,這就像是關於幾乎相同的事情的第六個問題......你真的在研究這個清單,不是嗎? – unwind 2011-04-07 10:09:00
[typedef和鏈表]的可能重複(http://stackoverflow.com/questions/5552394/typedef-and-linked-list) – JeremyP 2011-04-07 11:06:37