Rad
Riešenie
Úloha 14
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <string.h>
typedef struct uloha {
char nazov[30];
struct uloha *dalsi;
} TUloha;
------------------------------------------------------------------------------
void pridaj(TUloha **z, TUloha **k)
{
TUloha *p;
clrscr();
if (*z == NULL) {
*z = (TUloha*)malloc(sizeof(TUloha));
printf("nazov ulohy: ");
gets((*z)->nazov);
(*z)->dalsi = NULL;
*k = *z;
}
else {
p = (TUloha*)malloc(sizeof(TUloha));
printf("nazov ulohy: ");
gets(p->nazov);
p->dalsi = NULL;
(*k)->dalsi = p;
(*k) = p;
}
}
------------------------------------------------------------------------------
void vypis(TUloha *z1, TUloha *z2)
{
clrscr();
printf("Zoznam uloh - Front 1\n");
while (z1 != NULL) {
printf("\nuloha: %s", z1->nazov);
z1 = z1->dalsi;
}
printf("\n\nZoznam uloh - Front 2\n");
while (z2 != NULL) {
printf("\nuloha: %s", z2->nazov);
z2 = z2->dalsi;
}
getch();
}
------------------------------------------------------------------------------
void vybavenie(TUloha *z1, TUloha *z2) /* "tlač" úloh */
{
TUloha *pom;
clrscr();
printf("Prebieha tlac !!!\n");
while (z1 != NULL) {
pom = z1;
z1 = z1->dalsi;
printf("\nTlacim z F1: %s", pom->nazov);
free((void*)pom);
}
while (z2 != NULL) {
pom = z2;
z2 = z2->dalsi;
printf("\nTlacim z F2: %s", pom->nazov);
free((void*)pom);
}
getch();
}
------------------------------------------------------------------------------
int main(void)
{
TUloha *zac1, *kon1; /* prvý front */
TUloha *zac2, *kon2; /* druhý front */
int c;
zac1 = kon1 = NULL;
zac2 = kon2 = NULL;
/* menu */
do {
clrscr();
printf("Praca s dvoma tlacovymi frontami \n\n");
printf("Pridaj do F1................ 1\n");
printf("Pridaj do F2................ 2\n");
printf("Vybavenie................... 3\n");
printf("Vypis....................... 4\n\n");
printf("Koniec...................... k\n");
switch (c = getch()) {
case '1': pridaj(&zac1, &kon1); break;
case '2': pridaj(&zac2, &kon2); break;
case '3': {
vybavenie(zac1, zac2);
zac1 = kon1 = NULL;
zac2 = kon2 = NULL;
}
break;
case '4': vypis(zac1, zac2); break;
default: break;
}
} while (c != 'k');
return(0);
}
|