Форум программистов
 

Восстановите пароль или Зарегистрируйтесь на форуме, о проблемах и с заказом рекламы пишите сюда - alarforum@yandex.ru, проверяйте папку спам!

Вернуться   Форум программистов > C/C++ программирование > Общие вопросы C/C++
Регистрация

Восстановить пароль
Повторная активизация e-mail

Купить рекламу на форуме - 42 тыс руб за месяц

Ответ
 
Опции темы Поиск в этой теме
Старый 25.06.2009, 02:48   #1
vo_sa
Пользователь
 
Регистрация: 29.10.2008
Сообщений: 15
По умолчанию сортировка структуры

с
Код:
#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");
 }
}
vo_sa вне форума Ответить с цитированием
Старый 25.06.2009, 14:16   #2
Impuls1989
Форумчанин
 
Аватар для Impuls1989
 
Регистрация: 16.08.2008
Сообщений: 276
По умолчанию

А в чем собственно вопрос?
Искусственный интеллект - фигня по сравнению с естественной глупостью
Impuls1989 вне форума Ответить с цитированием
Ответ


Купить рекламу на форуме - 42 тыс руб за месяц

Опции темы Поиск в этой теме
Поиск в этой теме:

Расширенный поиск


Похожие темы
Тема Автор Раздел Ответов Последнее сообщение
Сортировка Шелла и Шейкер-сортировка AleksandrMakarov Паскаль, Turbo Pascal, PascalABC.NET 11 11.03.2012 12:18
структуры. не получается сортировка. grewnica Общие вопросы C/C++ 2 12.05.2009 14:49
Структуры. Сортировка по фамилии студента. STS_1991 Помощь студентам 3 09.05.2009 12:14
Структуры в СИ ManInBlack Помощь студентам 3 04.04.2009 19:08
[С++]Структуры...HELP!!! Настенька Помощь студентам 6 25.12.2007 21:11