void DeletePosition(node *first, node *last, int pos)
{
	node prev = NULL, cur = *first, temp;
	int i;
	if (pos <= 0 || pos > count)
	{
		printf("\nYou entered an invalid position.");
		return;
	}
	if (pos == 1) DeleteFront(first, last);
	else if (pos == count) DeleteRear(first, last);
	else
	{
		for (i = 1; i < pos; ++i)
		{
			prev = cur;
			cur = cur->rlink;
		}
		temp = cur;
		prev->rlink = cur->rlink;
		cur->rlink->llink = prev;
		free(temp);
	}
	--count;
}
예제 #2
0
int main()
{
    struct Queue *q = CreateQueue();
    InsertFront(q,1);
    InsertFront(q,3);
    InsertRear(q,0);
    InsertRear(q,5);
    printf("%d\n",DeleteFront(q)->element);
    printf("%d\n",DeleteRear(q)->element);
}
void main()
{
	node first = NULL, last = NULL;
	int i, ch;
	while (1)
	{
		printf("\nCIRCULAR LINKED LIST");
		printf("\n1. INSERT\n2. DELETE\n3. DISPLAY\n4. EXIT");
		printf("\nEnter your choice: ");
		scanf("%d", &i);
		//system("cls");
		//clrscr();
		switch (i)
		{
		case 1:
			printf("\n1. Insert at front");
			printf("\n2. Insert at rear");
			printf("\nEnter your choice: ");
			scanf("%d", &ch);
			switch (ch)
			{
			case 1: InsertFront(&first, &last);
				break;
			case 2: InsertRear(&first, &last);
				break;
			default: printf("\n You chose an invalid option.");
			}

			break;
		case 2: printf("\n1. Delete from front");
			printf("\n2. Delete from rear");
			printf("\nEnter your choice: ");
			scanf("%d", &ch);
			switch (ch)
			{
			case 1: DeleteFront(&first, &last);
				break;
			case 2: DeleteRear(&first, &last);
				break;
			default: printf("\n You chose an invalid option.");
			}

			break;
		case 3: Display(&first, &last);
			break;
		case 4: return;
		default: printf("\nInvalid choice. Try again.");
		}
	}
}