Kod: Zaznacz cały
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#include<conio.h>
struct Node
{
int data;
struct Node* next;
};
int isEmpty(struct Node*);
void push(struct Node**,int);
int pop(struct Node**);
int main()
{
int k;
int val;
struct Node * head;
head=NULL;
srand(time(NULL));
for(k=1; k<=24; k++)
{
val=rand()%100;
push(&head,val);
}
while(!isEmpty(head))
{
printf("%d \n",pop(&head));
}
while(!kbhit())
{
}
}
int isEmpty(struct Node* head)
{
return (head==NULL);
}
void push(struct Node** head,int n)
{
struct Node* newNode;
newNode=(struct Node*)malloc(sizeof(struct Node));
newNode->data=n;
newNode->next=(*head) ;
(*head)=newNode;
}
int pop(struct Node** head)
{
int val;
struct Node* temp;
if(!isEmpty(*head))
{
temp=(*head);
val=temp->data;
(*head)=(*head)->next;
free(temp);
return val;
}
else
{
printf("Struktura jest pusta\n");
return;
}
}
Nie udało mi się dodać funkcji aby struktura bardziej przypominała listę