示例#1
0
int main ( int argc, char *  args[])
{


node *head = NULL;

head = delete_at_end(head);
head = delete_at_first(head);
head = delete_at_position(head, 66);

head = insert_at_position (head, 2, 5 );
head = insert_at_first (head, 4 );
head = insert_at_position (head, 2, 3 );
head = insert_at_position (head, 2, 2 );
head = insert_at_position (head, 2, 1 );
print_linked_list (head);

head = delete_at_first(head);
head = delete_at_end(head);
head = delete_at_position (head, 2);
head = delete_at_position (head, 2);
head = delete_at_position (head, 2);


print_linked_list (head);
printf ("the length is %d\n" ,length_linked_list(head));

//printf ("successfully deleted list : %d\n", purge_linked_list(head));

return SUCCESS;
}
main()
{
	struct list *root=NULL;
	int choice,pos,val;
	printf("MENU : \n1.create\n2.insert at begin\n3.insert at end\n4.insert at pos\n5.delete at begin\n6.delete at end\n7.delete at pos\n8.display\n9.exit\n10.nth node from last\n");
	while(1)
	{
		printf("enter ur choice\n");
		scanf("%d",&choice);
		switch(choice)
		{
		case 1:
			if(root!=NULL)
			printf("list is already created\n");
			else
			{
				printf("enter value\n");
				scanf("%d",&val);
				root=insert_at_end(root,val);
				printf("list is created\n");
			}
			break;
		case 2:
			printf("enter value\n");
			scanf("%d",&val);
			root=insert_at_begin(root,val);
			printf("value is inserted at begin\n");
			break;
		case 3:
			printf("enter the value\n");
			scanf("%d",&val);
			root=insert_at_end(root,val);
			printf("val is inserted at end\n");
			break;
		case 4:
			printf("enter val\n");
			scanf("%d",&val);
			printf("enter pos\n");
			scanf("%d",&pos);
			root=insert_at_pos(root,val,pos);
			break;
		case 5:
			if(root==NULL)
				printf("nothing to delete\n");
			else
			{
				root=delete_at_begin(root);
				printf("node is deleted at begin\n");
			}
				break;
		case 6:
			if(root==NULL)
				printf("nothing to delete\n");
			else
			{
				root=delete_at_end(root);
				printf("node is deleted at end\n");
				
			}
			break;
		case 7:
			printf("enter pos\n");
			scanf("%d",&pos);
			root=delete_at_pos(root,pos);
			break;
		case 8:
			display(root);
			break;
		case 9:
			exit(0);
		case 10:
			printf("enter n value \n");
			scanf("%d", &pos);
			val=nth_node_val_from_last(root,pos);
			if(val!=777)
				printf("the nth node value from last is %d\n",val);
			break;
		}

	}

}