void main()
{
	node first = NULL, last = NULL;
	int i, pos;
	while (1)
	{
		printf("\nDOUBLY CIRCULAR LINKED LIST");
		printf("\n1. Insert - Front\n2. Insert - Rear\n3. Insert - Position\n4. Delete - Front");
		printf("\n5. Delete - Reart\n6. Delete - position\n7. Display\n8. Exit");
		printf("\nEnter your choice: ");
		scanf("%d", &i);
		//system("cls");
		//clrscr();
		switch (i)
		{
		case 1: InsertPosition(&first, &last, 1);
				break;
		case 2: InsertPosition(&first, &last, count + 1);
				break;
		case 3: printf("\nEnter the position where you want to insert the new node: ");
				scanf("%d", &pos);
				InsertPosition(&first, &last, pos);
				break;
		case 4: DeletePosition(&first, &last, 1);
				break;
		case 5: DeletePosition(&first, &last, count);
				break;
		case 6: printf("\nEnter the position from where you want to delete the a node: ");
				scanf("%d", &pos);
				DeletePosition(&first, &last, pos);
				break;
		case 7: Display(&first, &last);
				break;
		case 8: return;
		default: printf("\nInvalid choice. Try again.");
		}
	}
}
Esempio n. 2
0
/*插入函数*/
int insert(pStu pHead,pStu pInsert,int (*NameFind)(pStu,pStu),pStu (*InsertPosition)(pStu,pStu))
{
	int ret=0;
	pStu in_posi=NULL;

	ret = NameFind(pHead,pInsert);	
	if(ER==ret)
	{
		printf("不能插入\n");
		return ER;
	}
	else{
			in_posi = InsertPosition(pHead,pInsert);
			pInsert->next = in_posi->next;
			in_posi->next = pInsert;
		}
	return OK;
}