[ create a new paste ] login | about

Link: http://codepad.org/JeotcU4K    [ raw code | output | fork ]

C, pasted on Mar 26:
#include<stdio.h>
#include<stdlib.h>
#include "function.h"

Node* ReadOneList() {

	Node* new_stack = (Node*)malloc(sizeof(Node));
	int  card;

	scanf("%d:", &new_stack->size);
	new_stack->data = (int*)malloc(sizeof(int) * new_stack->size);

	for (int i = 0; i < new_stack->size; i++) {
		scanf(" %d", &new_stack->data[i]);
	}
	new_stack->next = NULL;

	return new_stack;
}

void PrintList(Node* dummy_head) {
	Node* head = dummy_head;
	dummy_head = dummy_head->next;

	while (dummy_head != NULL) {
		for (int i = 0; i < dummy_head->size - 1; i++) {
			printf("%d ", dummy_head->data[i]);
		}
		printf("%d\n", dummy_head->data[dummy_head->size - 1]);
		dummy_head = dummy_head->next;
	}

}

void Merge(Node* dummy_head, int x, int y) {
	Node* stack_x, * stack_y, * pre_stack_x;
	int* delete_card;
	int max = x > y ? x : y;

	for (int i = 0; i <= max;i++) {
		if (i == x - 1) {
			pre_stack_x = dummy_head;
		}
		if (i == x) {
			stack_x = dummy_head;
		}
		if (i == y) {
			stack_y = dummy_head;
			delete_card = stack_y->data;
		}

		dummy_head = dummy_head->next;
	}
		
	int* card = (int*)malloc(sizeof(int) * (stack_y->size + stack_x->size));

	for (int i = 0; i < stack_y->size; i++) {
		card[i] = stack_y->data[i];
	}
	for (int i = 0; i < stack_x->size; i++) {
		card[i+stack_y->size]= stack_x->data[i];
	}

	stack_y->size = stack_x->size + stack_y->size;
	stack_y->data = card;
	pre_stack_x->next = stack_x->next;
	free(delete_card);
	free(stack_x);
}

void Cut(Node* dummy_head, int x, int y) {
	Node* stack_x = dummy_head;
	Node* new_stack = (Node*)malloc(sizeof(Node));

	for (int i = 0; i < x; i++) {
		stack_x = stack_x->next;
	}

	int* split_card = (int*)malloc(sizeof(int) * (stack_x->size - y));
	int* original_card = (int*)malloc(sizeof(int) * y);
	for (int i = 0; i < y; i++) {
		original_card[i] = stack_x->data[i];
	}
	for (int i = 0; i < stack_x->size-y; i++) {
		split_card[i] = stack_x->data[i + y];
	}

	new_stack->next = stack_x->next;
	stack_x->next = new_stack;

	new_stack->size = stack_x->size - y;
	stack_x->size = y;

	free(stack_x->data);

	stack_x->data = original_card;
	new_stack->data = split_card;
}


Output:
1
2
3
4
5
Line 21: error: function.h: No such file or directory
Line 5: error: expected '=', ',', ';', 'asm' or '__attribute__' before '*' token
Line 21: error: expected ')' before '*' token
Line 35: error: expected ')' before '*' token
Line 71: error: expected ')' before '*' token


Create a new paste based on this one


Comments: