rendered paste body#include <stdio.h>
#include <malloc.h>
#include <string.h>
struct Tlista_jedn{
char dane[20];
struct Tlista_jedn *nast;
};
void wyswietl_liste(struct Tlista_jedn *head){
struct Tlista_jedn *pom;
int i=1;
pom=head;
if(head==NULL)
printf("Lista jest pusta !\n");
else{
while(pom!=NULL){
printf("Element %d : %s",i,pom->dane);
pom=pom->nast;
i++;
}
}
system("pause");
}
void usun_el(struct Tlista_jedn *head){
struct Tlista_jedn *pom,*pom1;
char el_do_us[20];
printf("Oto lista:\n");
wyswietl_liste(head);
if(head!=NULL){
printf("Podaj element do usuniecia:");
fgets(el_do_us,20,stdin);
pom=head;
while(strcmp(pom->dane,el_do_us)!=0)
pom=pom->nast;
pom1=pom;
pom1=pom1->nast;
pom->nast=NULL;
free(pom);
}
}
void dodaj_el(struct Tlista_jedn **head){
struct Tlista_jedn *pom,*nowy;
nowy=(struct Tlista_jedn*)malloc(sizeof(struct Tlista_jedn));
printf("Podaj dane:");
fgets(nowy->dane,20,stdin);
pom=*head;
if(*head==NULL){
nowy->nast=NULL;
*head=nowy;
}else{
while(pom->nast!=NULL)
pom=pom->nast;
nowy->nast=NULL;
pom->nast=nowy;
}
}
void main(void){
struct Tlista_jedn *head=NULL;
char wybor;
do{
printf("Co chcesz zrobic?\n");
printf("1 - Dodaj do listy \n");
printf("2 - Wyswietl liste \n");
printf("3 - Usun element \n");
printf("q - quit \n\n");
printf("Wybieram : ");
scanf("%c",&wybor);
fflush(stdin);
switch(wybor){
case '1': dodaj_el(&head); break;
case '2': wyswietl_liste(head); break;
case '3': usun_el(head); break;
}
system("cls");
}while(wybor!='q');
system("pause");
}