с
Код:
#include "stdafx.h"
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <conio.h>
#include <math.h>
#include <ctype.h>
#include <float.h>
struct queueNode //структура со ссылкой на себя
{
char name;// наименование
float plsh;// площадь
int etzh; // этажность
int gdsr; // год сооружения
float stm;// стоймость млн.руб.
struct queueNode *nextPtr;
};
typedef struct queueNode QueueNode;
typedef QueueNode *QueueNodePtr;
/*прототипы функций*/
void printQueue ( QueueNodePtr );
int isEmpty(QueueNodePtr);
char dequeue(QueueNodePtr *, QueueNodePtr * );
void enqueue(QueueNodePtr *, QueueNodePtr * , char, float, int, int, float);
void instructions (void);
int main()
{
QueueNodePtr headPtr = NULL, tailPtr = NULL;
int choice;
char item;
float item2;
int item3;
int item4;
float item5;
instructions();
printf("?");
scanf("%d", &choice);
while (choice !=3) {
switch( choice ) {
case 1:
printf("vvedite naimenovanie: ");
scanf("\n%c", &item); //считваем как char
printf("vvedite a ploshad': ");
scanf("\n%f", &item2); //считваем как float
printf("vvedite etazhnost': ");
scanf("\n%d", &item3); //считваем как int
printf("vvedite god sooruzhenia: ");
scanf("\n%d", &item4); //считваем как int
printf("vvedite stoimost': ");
scanf("\n%f", &item5); //считваем как float
enqueue( &headPtr, &tailPtr, item, item2, item3, item4, item5); // - для 5 элементов
printQueue( headPtr);
break;
case 2:
if ( !isEmpty(headPtr )){
item = dequeue (&headPtr, &tailPtr);
printf("%c%d has been dequeue.\n",item);
}
printQueue( headPtr);
break;
default:
printf("Invalid choice\n\n");
instructions();
break;
}
printf("?");
scanf("%d", &choice);
}
printf("End of run\n");
return 0;
}
void instructions (void)
{
printf("Enter your choice:\n"
"1 to add an item to the queue\n"
"2 to remove an item from the queue\n"
"3 to end\n");
}
void enqueue (QueueNodePtr *headPtr, QueueNodePtr *tailPtr , char value, float value2, int value3, int value4, float value5)
{
QueueNodePtr newPtr;
newPtr = (QueueNode*)malloc(sizeof (QueueNode));
if (newPtr != NULL)
{
newPtr->name=value;
newPtr->plsh=value2;
newPtr->etzh=value3;
newPtr->gdsr=value4;
newPtr->stm=value5; // добавим 5 значениq в структуру
newPtr->nextPtr = NULL;
if (isEmpty (* headPtr))
*headPtr=newPtr;
else
(*tailPtr)->nextPtr = newPtr;
*tailPtr = newPtr;
}
else
printf("%c not insert. No memory availavble.\n", value);
}
char dequeue(QueueNodePtr *headPtr, QueueNodePtr *tailPtr )
{
char value;
float plsh;// площадь
int etzh; // этажность
int gdsr; // год сооружения
float stm;// стоймость млн.руб.
QueueNodePtr tempPtr;
value = (*headPtr)->name;
plsh = (*headPtr)->plsh;
etzh = (*headPtr)->etzh;
gdsr = (*headPtr)->gdsr;
stm = (*headPtr)->stm;
tempPtr = *headPtr;
*headPtr = (*headPtr)->nextPtr;
if(*headPtr == NULL)
*tailPtr = NULL;
free (tempPtr);
return value;
}
int isEmpty(QueueNodePtr headPtr)
{
return headPtr == NULL;
}
void printQueue (QueueNodePtr currentPtr)
{
int i=0;
if (currentPtr == NULL)
printf ("Queue is empty\n\n");
else{
printf("The queue is:\n");
while(currentPtr != NULL)
{
i++;
printf("\nAeraport %d\n", i);
printf("naimenovanie %c --> ", currentPtr->name);
printf("ploshad' %6.2f --> ", currentPtr->plsh);
printf("etazhnost' %d --> ", currentPtr->etzh);
printf("god %d --> ", currentPtr->gdsr);
printf("stoimost' %6.2f --> ", currentPtr->stm);
printf("\n ");
currentPtr = currentPtr->nextPtr;
}
for(i=0;i<n;i++)
{
queueNode[i].gdsr > queueNode[i+1].gdsr
}
currentPtr->plsh
printf("NULL\n\n");
}
}