Witam
Muszę napisać program, w którym można dodawać, usuwać itd. elementy ze stosów. Stos zwykły napisałem już, teraz muszę jakoś to przekształcić, żeby elementy dodawały się do wybranego stosu, jednego z kilku.
Chodzi mi przede wszystkim o to, co mam zrobić, żeby po wpisaniu "push_s 1 2", do stosu nr 1 została dodana wartość 2. Jak będę umiał to zrobić, to z resztą polecenia sobie poradzę. Mógłby mi ktoś, kto zna się na tablicach struktur powiedzieć jak mam to zrobić?
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct elem
{
int x;
struct elem* next;
} *head = NULL;
struct elem struktury[9];
void push(int x)
{
struct elem* nowy = (struct elem*)malloc(sizeof(struct elem));
nowy -> next = head;
nowy -> x = x;
head = nowy;
}
int pop()
{
struct elem *stary = head;
head = head -> next;
int x = stary -> x;
free(stary);
return x;
}
int main()
{
char polecenie[20];
int liczba, numer1, numer2;
while(~scanf("%s %d", &polecenie, &numer1))
{
if(strcmp(polecenie, "new_s") == 0)
{
printf("ok, new_s %d\n", numer1);
}
if(strcmp(polecenie, "push") == 0)
{
scanf("%d", &liczba);
printf("ok, push %d %d\n", numer1, liczba);
}
if(strcmp(polecenie, "stack->stack") == 0)
{
scanf("%d", &numer2);
printf("ok, stack->stack %d %d\n", numer1, numer2);
}
if(strcmp(polecenie, "delete_s") == 0)
{
printf("ok, delete_s %d\n", numer1);
}
if(strcmp(polecenie, "print_s") == 0)
{
printf("ok, print_s %d\n", numer1);
}
/*{
scanf("%d", &liczba);
push(liczba);
printf("OK\n");
}
if(znak == '-')
{
if(head != NULL) printf("%d", pop());
else printf("BLAD\n");
}*/
}
return 0 ;
}