Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- struct elem{
- int Messwert;
- int Anz;
- struct elem *next;
- struct elem *prev;
- };
- struct elem *root;
- struct elem *tail;
- void list_init(void){
- root=tail=NULL;
- }
- void list_bind( int m){
- struct elem *ptr, *ptr1;
- if(tail==NULL){
- if((tail=malloc(sizeof(struct elem))) == NULL){
- fprintf(stderr, "ERROR");
- return;
- }
- }
- if(root==NULL){
- if((root=malloc(sizeof(struct elem))) == NULL){
- fprintf(stderr, "ERROR");
- return;
- }
- root->Messwert=m;
- root->next=NULL;
- tail=root;
- tail->prev=NULL;
- } else {
- ptr=root;
- while(ptr->next != NULL)
- ptr=ptr->next;
- if((ptr->next=malloc(sizeof(struct elem))) == NULL){
- fprintf(stderr, "ERROR");
- return;
- }
- ptr1=ptr;
- ptr=ptr->next;
- ptr->Messwert=m;
- ptr->next=NULL;
- tail=ptr;
- ptr->prev=ptr1;
- ptr1->next=ptr;
- }
- }
- void eingabe(void){
- int mess;
- printf("Bitte geben sie Eine Messwert: ");
- scanf("%d", &mess);
- list_bind(mess);
- }
- void ausgabe(void){
- struct elem *ptr;
- ptr=root;
- while(ptr != NULL){
- printf("MESSWERT %d\n", ptr->Messwert);
- ptr=ptr->next;
- }
- }
- struct elem *LstSuchInc(struct elem *wrz, int ulWert){
- struct elem *currentElement=wrz;
- currentElement=root;
- if(currentElement != NULL){
- while (currentElement != NULL) {
- if (currentElement->Messwert == ulWert) {
- (currentElement->Anz)++;
- return currentElement;
- }
- currentElement = currentElement->next;
- }
- } else return 0;
- }
- void SuchErgebniss(void){
- struct elem *mwert;
- int data;
- printf("Bitte geben sie Ein wert: ");
- scanf("%d", &data);
- mwert=LstSuchInc(root, data);
- if(mwert){
- printf("Element %d Found\n", mwert->Messwert);
- printf("Element %d %d mal aufgetreten!\n", mwert->Messwert, mwert->Anz);
- } else {
- printf("Element Not Found\n");
- }
- }
- int getLast(struct elem *wrz){
- int current=wrz->Messwert;
- int next;
- if(wrz->next==NULL){
- return current;
- } else {
- next=getLast(wrz->next);
- }
- if(current>next)
- return current;
- else
- return next;
- }
- void getLastErg(void){
- int erg;
- erg=getLast(root);
- printf("The last Big Element ist: %d", erg);
- }
- void LstInsert(struct elem *neu, struct elem *last){
- struct elem *ptr;
- if(root==NULL){
- printf("Keine Elemente vorhanden!\n");
- return;
- } else {
- ptr=root;
- while(ptr!=NULL){
- ptr=ptr->next;
- if(ptr==NULL){
- ptr=last;
- last->next=neu;
- neu=malloc(sizeof(struct elem));
- neu->Messwert=ptr->Messwert;
- neu->next=NULL;
- }
- }
- }
- }
- int CalcMittel(void){
- struct elem *ptr;
- int temp=0, summe=0;
- ptr=root;
- while(ptr!=NULL){
- ptr=ptr->next;
- summe=summe+ptr->Messwert;
- temp++;
- }
- return summe/temp;
- }
- void mittelwerterg(void){
- int m;
- m=CalcMittel();
- printf("Das Mittelwert ist %d", m);
- }
- int main(void) {
- int wahl;
- list_init();
- do {
- printf("\n1 : Eingabe\n");
- printf("2 : Ausgabe\n");
- printf("3 : List Suche\n");
- printf("4 : Get Last\n");
- printf("5 : Mittelwert\n");
- printf("9 : Ende\n");
- printf("Ihre Wahl : ");
- scanf("%d",&wahl);
- getchar();
- switch(wahl) {
- case 1 : eingabe();
- break;
- case 2 : ausgabe();
- break;
- case 3 : SuchErgebniss();
- break;
- case 4 : getLastErg();
- break;
- case 5 : mittelwerterg();
- case 9 : break;
- default: printf("Falsche Eingabe!!!\n");
- }
- } while(wahl != 9);
- return EXIT_SUCCESS;
- }
Advertisement
Add Comment
Please, Sign In to add comment