Last active
May 30, 2017 16:04
-
-
Save skhozinova/9caec5ae1df38f864f182d809fc9b63d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<stdio.h> | |
#include<conio.h> | |
#include<stdlib.h> | |
// Создать список из целых чисел. Подсчитать сумму положительных элементов. Создать из них новый список. | |
struct tqueue // описание очереди | |
{ | |
int inf; | |
tqueue *next; | |
}; | |
tqueue *head,*tail; | |
void init_queue(tqueue *&h, tqueue *&t)//инициализация очереди | |
{ | |
h=t=NULL; | |
} | |
void insert(tqueue *&h,tqueue *&t, int item)//добавление элемента | |
{ | |
tqueue *r=new tqueue; | |
r->inf=item; | |
r->next=NULL; | |
if (!h&&!t) | |
h=t=r; | |
else | |
{ | |
t->next=r; | |
t=r; | |
} | |
} | |
int take(tqueue *&h, tqueue *&t)//удаление элемента | |
{ | |
tqueue *y=h; | |
int j=y->inf; | |
h=y->next; | |
if (!h) | |
t=NULL; | |
delete y; | |
return j; | |
} | |
int print_list(tqueue *head) //пустота ссылки | |
{ | |
int num=0; | |
tqueue *h = head; | |
while (h!= NULL) | |
{ | |
if(h->inf<0) | |
{ | |
num++; | |
h = h->next; | |
} | |
} return num; | |
} | |
int main(void) | |
{ | |
FILE *h=fopen("in.txt","r"); | |
int x=0; | |
init_queue(head,tail);//инициализация очереди | |
while (!feof(h)) //пока не достигнут конец файла h | |
{ | |
fscanf(h,"%d",&x); //читаем целое число из файла в переменную x | |
insert(head,tail,x); | |
} | |
x=print_list(head); | |
printf("%d",x);//записываем его в файл g | |
fcloseall(); //завершаем работу с файлами | |
system("pause"); | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-9 | |
-10 | |
-33 | |
-89 | |
-12 | |
-7 | |
-2 | |
-45 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment