Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <conio.h>
- #include <math.h>
- #include <alloc.h>
- FILE *fin, *fout;
- typedef struct list
- {
- int data;
- list *next; // âêàç³âíèê íà íàñòóïíèé åëåìåíò ÷åðãè
- } queue;
- void add(queue* &head, queue *&pt, int a) // ôóíêö³ÿ ðîçì³ùåííÿ íîâîãî åëåìåíòó â ÷åðç³
- {
- queue *temp = new queue;
- //temp = (queue*)calloc(1, sizeof(queue));
- temp -> data = a;
- temp -> next = NULL;
- if(head == NULL) head = temp;
- else pt -> next = temp;
- pt = temp;
- }
- void input(queue *&head) // ôóíêö³ÿ ââåäåííÿ ÷åðãè
- {
- int M, data;
- queue *pt;
- fscanf(fin, "%d", &M);
- for(int i = 0; i < M; i++)
- {
- fscanf(fin, "%d", &data);
- add(head, pt, data);
- }
- }
- void print(queue *head) // ôóíêö³ÿ âèâåäåííÿ ÷åðãè
- {
- queue *temp = head -> next;
- while(temp)
- {
- fprintf(fout, "%d ", temp -> data);
- temp = temp -> next;
- }
- }
- void parse(queue *&head, queue *&head1, queue *&head2)
- {
- queue *pt, *pt1, *pt2;
- pt = head;
- while(pt)
- {
- if(pt -> data >= 0) add(head1, pt1, pt -> data);
- else add(head2, pt2, pt -> data);
- }
- }
- int main()
- {
- queue *head = NULL, *head1 = NULL, *head2 = NULL;
- fin = fopen("input.txt" , "r");
- fout = fopen("output.txt" , "w");
- input(head);
- parse(head, head1, head2);
- fprintf(fout, "ïàðí³ ÷èñëà: \n"); print(head1);
- fprintf(fout, "íåïàðí³ ÷èñëà: \n"); print(head2);
- fclose(fin);
- fclose(fout);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement