Welcome, guest! Login / Register - Why register?
Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)

Paste

Pasted as C by agro ( 15 years ago )
#include <stdio.h>
#include <conio.h>
#include <alloc.h>
#include <string.h>


struct edition
{
 char title[20]; //название издания
 char  type[8]; // тип: газета или журнал
 int price; //цена экземпляра

 struct edition *prev; //указатель на предыдущую структуру
 struct edition *next; //указатель на  следующую структуру
};

struct edition *head, *tail; //указатели на начало и конец списка

//описание прототипов функций

void input();
void create(void); // создание списка структур
void list(edition *); // просмотр списка
void app(edition *p); // добавление в конец списка новой структуры
void edit(); // корректировка списка
int scount();
//void sort(); //сортировка по алфавиту

int count; //колличество записей;


int main()
{
 char c;
 while (1)
 {
  clrscr();
  puts(" 1 - Sozdanie spiska");
  puts(" 2 - Prosmotr spiska");
  puts(" 3 - Dobavlenie v konec spiska");
  puts(" 4 - Korrektirovka spiska");
  puts(" 0 - Exit");
  c=getch();

  switch(c)
   {
    case '1':create();break;
    case '2':list(head); break;
    case '3':app(tail);break;
    case '4':edit();break;
      case '0':return 0;
    default : puts(" Neverniy rezhim");
   }
 }

 return 0;
}


void create(void)
{
 char ch;
 clrscr();
 edition *p,*pred;
 pred=NULL;
count = 0;
 printf("Zapolnenie spiska izdaniy.\n\n");
   do
   {
    p=(edition *)malloc(sizeof(edition));

    printf("Nazvanie izdaniya: "); scanf("%s",p->title);
    printf("Tip izdaniya (Gazeta, Journal): "); scanf("%s",p->type);
    printf("Cena ekzemplyara: "); scanf("%d",&p->price);
count++;
    p->prev=pred;
    if (pred != NULL)
      pred->next=p;
    else
      head=p;
    pred=p;
    puts("\nZakonchit? y/n ");
    ch=getch();
    printf("\n");
   }
   while (ch !='y');

  tail=p;
  tail->next=NULL;
}

void list(edition *p)
{
 int i;
 clrscr();
 if (p==head)
{
i = 1;
  while (p != NULL)
    {

      printf("= Nazvanie  s Tip %8s Cena izdaniya M \n", i, p->title, p->type, p->price);
      p=p->next;
    i++;
    }
}
   else if (p==tail)
{
i = count;
    while ( p!= NULL)
    {
     printf("= Nazvanie  s Tip %8s Cena izdaniya M \n", i, p->title, p->type, p->price);
     p=p->prev;
i--;
    }
}
   else
    puts("Neverniy adres  ");
    getch();
  }

void app(edition *p) //добавление в конец списка. переходим в конец, выделяем память, заполняем как в create(), изменяем pred->next на текущее. p->prev = pred.
{
char ch;

 edition *pn;
 clrscr();
 printf("Dobavlenie v konec spiska.\n\n");
   do
   {
   pn=(edition *)malloc(sizeof(edition));
    printf("Nazvanie izdaniya: "); scanf("%s",pn->title);
    printf("Tip izdaniya (Gazeta, Journal): "); scanf("%s",pn->type);
    printf("Cena ekzemplyara: "); scanf("%d",&pn;->price);
    count++;
pn->prev=tail;
pn->next=NULL;
p->next=pn;
tail=pn;
p = tail;
    puts("\nZakonchit? y/n ");
    ch=getch();
    printf("\n");
   }

   while (ch !='y');
}

void edit()
{
 int i = 1;
 int x = 0;
 char title[20], type[8];
 int price;
 edition *p, *ps, *tmp, *p2, *tmp2;
 clrscr();
 printf("Sortirovka spiska po alfavitu..\n\n");

 p = head;
 ps = p->next;
 if (p->next == NULL)
  printf("Spisok soderzhit nedostatochno elemtov dlya sortirovki.\n");
 else
  {
  do
   {
    printf("cikl %d: p->title = %s ps->title = %s\n", i, p->title, ps->title);

    if (strcmp(p->title, ps->title) > 0 )
     {
      strcpy(tmp->title,p->title);
      strcpy(tmp->type,p->type);
      tmp->price = p->price;

      strcpy(p->title,ps->title);
      strcpy(p->type,ps->type);
      p->price = ps->price;

      strcpy(ps->title,tmp->title);
      strcpy(ps->type,tmp->type);
      ps->price = tmp->price;


     }

     if (ps->next == NULL)
     {
      p = head;
      ps = p->next;
      x++;
     }
     else
     {
      p = ps;
      ps = ps->next;
     }

    i++;

   } while(x != scount());

  printf("Sortirovka zakonchena.");
  } //else
 getch();

}

int scount()
{
 edition *p = head;
 int x = 1;
  while(p->next != NULL)
   {
    x++;
    p = p->next;
   }
 return x;

}

 

Revise this Paste

Your Name: Code Language: