Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // uloha-9-1.c -- Tyzden 9 - Uloha 1
- // Michal Kovacik, 15.4.2014 07:07:46
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- typedef struct tovar{
- char nazov[100];
- char vyrobca[100];
- double mnozstvo;
- double cena;
- }TOVAR;
- int main(){
- TOVAR *p = NULL, pom;
- char prikaz[10];
- int zaznamov = 0, i, j, maxZaznamov = 100;
- p = (TOVAR*)malloc(maxZaznamov * sizeof(TOVAR));
- while (scanf("%s", prikaz)!=EOF){
- if (zaznamov == maxZaznamov){
- maxZaznamov *= 2;
- p = (TOVAR*)realloc(p, maxZaznamov * sizeof(TOVAR));
- }
- if (!strcmp("vloz", prikaz)){
- scanf("%s", (p + zaznamov)->nazov);
- scanf("%s", (p + zaznamov)->vyrobca);
- scanf("%lf", &(p + zaznamov)->mnozstvo);
- scanf("%lf", &(p + zaznamov)->cena);
- zaznamov++;
- for (j = zaznamov; j > 0; j--){
- for (i = 1; i < j; i++){
- if (strcmp((p + i - 1)->nazov, (p + i)->nazov)>0){
- pom = *(p + i - 1);
- *(p + i - 1) = *(p + i);
- *(p + i) = pom;
- }
- }
- }
- }
- if (!strcmp("vypis", prikaz)){
- for (i = 0; i < zaznamov; i++){
- printf("Nazov=%s, Vyrobca=%s, Mnozstvo=%lf, JednotkovaCena=%lf\n", (p + i)->nazov, (p + i)->vyrobca, (p + i)->mnozstvo, (p + i)->cena);
- }
- putchar('\n');
- }
- }
- return 0;
- }
- // uloha-9-1.c -- Tyzden 9 - Uloha 2
- // Michal Kovacik, 15.4.2014 09:07:46
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- typedef struct tovar{
- char nazov[100];
- char vyrobca[100];
- char mnozJednotka[3];
- double mnozstvo;
- double cena;
- struct tovar *dalsi;
- }TOVAR;
- int main(){
- TOVAR *prvy = NULL, *akt = NULL, *novy = NULL;
- char prikaz[20];
- int size = 0;
- while (scanf("%s", prikaz) != EOF){
- if (!strcmp("vloz", prikaz)){
- novy = (TOVAR*)malloc(sizeof(TOVAR));
- scanf("%s %s %lf %lf %s", novy->nazov, novy->vyrobca, &novy->mnozstvo, &novy->cena, novy->mnozJednotka);
- novy->dalsi = NULL;
- if (prvy == NULL){
- prvy = novy;
- size++;
- }
- else{
- akt = prvy;
- if (strcmp(prvy->nazov, novy->nazov) >= 0){
- novy->dalsi = prvy;
- prvy = novy;
- size++;
- }
- else{
- while (akt->dalsi != NULL && strcmp(akt->dalsi->nazov, novy->nazov) <= 0)
- akt = akt->dalsi;
- novy->dalsi = akt->dalsi;
- akt->dalsi = novy;
- size++;
- }
- }
- }
- if (!strcmp("vypis", prikaz)){
- akt = prvy;
- while (akt != NULL){
- printf("Nazov=%s, Vyrobca=%s, Mnozstvo=%lf, JednotkovaCena=%lf, MJ=%s\n", akt->nazov, akt->vyrobca, akt->mnozstvo, akt->cena, akt->mnozJednotka);
- akt = akt->dalsi;
- }
- putchar('\n');
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement