Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <stdlib.h>
- #include <stdio.h>
- #include <string.h>
- #include <conio.h>
- #include <locale.h>
- typedef struct Team {
- int Name;
- int City;
- int Wins;
- int Loses;
- int Draws;
- int Points;
- struct Team*Next;
- }Team;
- typedef struct List
- {
- Team*First;
- }List;
- void Add(List* L, int *N) {
- Team*Current = L->First;
- Team *time = (Team*)calloc(1, sizeof(Team));
- printf("Name ");
- scanf_s("%d", &time->Name);
- printf("\nCity ");
- scanf_s("%d", &time->City);
- printf("\nWins ");
- scanf_s("%d", &time->Wins);
- printf("\nLoses ");
- scanf_s("%d", &time->Loses);
- printf("\nDraws");
- scanf_s("%d", &time->Draws);
- printf("\nPoints ");
- scanf_s("%d", &time->Points);
- while (Current->Next != NULL)
- Current =Current->Next;
- Current->Next = time;
- time->Next = NULL;
- (*N)++;
- }
- Team* Find(List*L, int *N) {
- printf("\Print Team name");
- int i, n;
- Team* Current=L->First;
- scanf_s("%d", &n);
- while ((Current->Name != n)&&(Current!=NULL))
- Current = Current->Next;
- if (Current->Name != n)
- return 0;
- FILE* fl;
- fopen_s(&fl, "test.txt", "a");
- fprintf(fl, "\n%d ", Current->Name);
- fprintf(fl, "%d ", Current->City);
- fprintf(fl, "%d ", Current->Wins);
- fprintf(fl, "%d ", Current->Loses);
- fprintf(fl, "%d ", Current->Draws);
- fprintf(fl, "%d \n", Current->Points);
- fclose(fl);
- return Current;
- }
- void Insert(List* L, int*N)
- {
- printf("Print place where to insert element");
- int m,i;
- scanf("%d",&m);
- Team* Current=L->First;
- Team *time=(Team*)calloc(1,sizeof(Team));
- printf("Name ");
- scanf_s("%d", &time->Name);
- printf("\nCity ");
- scanf_s("%d", &time->City);
- printf("\nWins ");
- scanf_s("%d", &time->Wins);
- printf("\nLoses ");
- scanf_s("%d", &time->Loses);
- printf("\nDraws ");
- scanf_s("%d", &time->Draws);
- printf("\Points");
- scanf_s("%d", &time->Points);
- if (m == *N+1)
- while (Current->Next!=NULL) {
- Current= Current->Next;
- }
- if (m == 0) {
- time->Next = L->First;
- L->First=time;
- }
- if (m ==* N) {
- Current->Next = time;
- time->Next == NULL;
- }
- if ((m != *N+1) && (m != 0)) {
- for (int i = 0; i < m-1; i++)
- Current = Current->Next;
- time->Next = Current->Next;
- Current->Next = time;
- }
- (*N)++;
- }
- List filtr(List*L, int*N) {
- printf("\n Print filter number ");
- List now;
- now.First = NULL;
- Team* Current=L->First,*Current2=now.First;
- int otv,p;
- int i;
- scanf_s("%d", &p);
- printf("\n1->\n2-<\n3-=");
- scanf_s("%d", &otv);
- *N = 0;
- switch (otv) {
- case 1: while (Current != NULL) {
- if (Current->Wins > p) {
- if (now.First == NULL) {
- now.First = (Team*)calloc(1, sizeof(Team));
- now.First = Current;
- (*N)++;
- Current2 = now.First;
- Current= Current->Next;
- continue;
- }
- if(Current2!=NULL) {
- Current2->Next = (Team*)calloc(1, sizeof(Team));
- Current2->Next = Current;
- Current2 = Current2->Next;
- (*N)++;
- }
- }
- Current = Current->Next;
- }
- break;
- case 2: while (Current != NULL) {
- if (Current->Wins < p) {
- if (now.First == NULL) {
- now.First = (Team*)calloc(1, sizeof(Team));
- now.First = Current;
- (*N)++;
- Current2 = now.First;
- Current = Current->Next;
- continue;
- }
- if (Current2 != NULL) {
- Current2->Next = (Team*)calloc(1, sizeof(Team));
- Current2->Next = Current;
- Current2 = Current2->Next;
- (*N)++;
- }
- }
- Current = Current->Next;
- }
- break;
- case 3: while (Current != NULL) {
- if (Current->Wins== p) {
- if (now.First == NULL) {
- now.First = (Team*)calloc(1, sizeof(Team));
- now.First = Current;
- (*N)++;
- Current = now.First;
- Current = Current->Next;
- continue;
- }
- if (Current2 != NULL) {
- Current2->Next = (Team*)calloc(1, sizeof(Team));
- Current2->Next = Current;
- Current2 = Current2->Next;
- (*N)++;
- }
- }
- Current = Current->Next;
- }
- break;
- }
- return now;
- }
- void Remove(List* L,int*N,Team*Delete)
- {
- Team*Current=L->First;
- if(Delete->Name!=L->First->Name){
- if (Current->Name !=Delete->Name) {
- while (Current->Next->Name != Delete->Name)
- Current = Current->Next;
- }
- Current->Next = Current->Next->Next;
- }
- else
- L->First = Current->Next;
- (*N)--;
- }
- void save(List* L,int*N) {
- FILE* fl=fopen("test1.txt", "a");
- int i;
- Team*Current;
- Current= L->First;
- fprintf(fl, "\n ");
- for (i = 0; i < *N; i++) {
- fprintf(fl, "%d ", Current->Name);
- fprintf(fl, "%d ", Current->City);
- fprintf(fl, "%d ", Current->Wins);
- fprintf(fl, "%d ", Current->Loses);
- fprintf(fl, "%d ", Current->Draws);
- fprintf(fl, "%d \n",Current->Points);
- Current = Current->Next;
- }
- fclose(fl);
- }
- void load(List*L,int* N) {
- FILE* fl=fopen("test.txt","r");
- int i;
- Team*Current = L->First;
- fscanf_s(fl, "%d", N);
- for (i = 0; i <*N; i++) {
- fscanf_s(fl, "%d",&Current->Name);
- fscanf_s(fl, "%d",& Current->City);
- fscanf_s(fl, "%d", &Current->Wins);
- fscanf_s(fl, "%d", &Current->Loses);
- fscanf_s(fl, "%d", &Current->Draws);
- fscanf_s(fl, "%d", &Current->Points);
- Current->Next = (Team*)calloc(1,sizeof(Team));
- if (1+i == *N)
- Current->Next = NULL;
- Current = Current->Next;
- }
- fclose(fl);
- }
- int main()
- {
- int N;
- List L;
- Team* c;
- L.First = (Team*)calloc(1,sizeof(Team));
- load(&L,&N);
- save(&L,&N);
- Insert(&L, &N);
- save(&L, &N);
- Remove(&L, &N, Find(&L, &N));
- save(&L, &N);
- Add(&L, &N);
- save(&L, &N);
- save(&filtr(&L, &N),&N );
- free(L.First);
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement