Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

2K_programuvanna / 3 mod / 14

.2.2.C
Скачиваний:
26
Добавлен:
19.04.2015
Размер:
1.57 Кб
Скачать
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
 typedef struct st1 {
	int info;
	struct st1 *prev;
 } QUOTE;

 void add(QUOTE **head_1, QUOTE **tail_1, int item);
 int shift(QUOTE **head_1, QUOTE **tail_1);

 int main(){
	QUOTE *head_1 = NULL, *tail_1 = NULL;
	QUOTE *head_2 = NULL, *tail_2 = NULL;
	QUOTE *head_3 = NULL, *tail_3 = NULL;
	int i,value,value_1,value_2;
	clrscr();
	for (i=0; i<5; i++){
		printf("Vvedite element %d:", i+1);
		scanf("%d",&value);
		add(&tail_1,&head_1,value);
	}
	for (i=0; i<5; i++){
		printf("Vvedite element %d:", i+1);
		scanf("%d",&value);
		add(&tail_2,&head_2,value);
	}
	while (head_1 && head_2){

		if(head_1->info<head_2->info){
			add(&tail_3,&head_3,shift(&tail_1,&head_1));

		}
		else{
			add(&tail_3,&head_3,shift(&tail_2,&head_2));

		}
	}
		while(head_2)

				add(&tail_3,&head_3,shift(&tail_2,&head_2));


		while(head_1)
				add(&tail_3,&head_3,shift(&tail_1,&head_1));



	while (head_3){
		printf("%d ",shift(&tail_3,&head_3));
	}
	puts("\n");
	return 0;
 }

 void add(QUOTE **tail_1, QUOTE **head_1, int item){
	QUOTE *new_item;
	new_item = (QUOTE*)malloc(sizeof(QUOTE));
	new_item -> info = item;
	new_item -> prev = NULL;
	(**tail_1).prev = new_item;
	*tail_1 = new_item;
	if (*head_1==NULL){
		*head_1 = new_item;
	}
 }
 int shift(QUOTE **tail_1, QUOTE **head_1){
	QUOTE * element = *head_1;
	int value = element->info;
	*head_1 = (**head_1).prev;
	free(element);
	if (*head_1==NULL){
		*tail_1 = NULL;
	}
	return value;
 }
Соседние файлы в папке 3 mod