Пример #1
0
struct node * create(struct node *root)
{
	struct node *temp;
	int num,i=0;

	if(root==NULL)
	{
		printf("enter no of nodes to be created");
		scanf("%d",&num);
		while(i<num)
		{
			if(i==0)
			{
		temp=(struct node *)malloc(sizeof(struct node));
		printf("enter the value");
		scanf("%d",&temp->value);
		temp->next=NULL;
		root=temp;
			}
			else 
			{
				root=insertatend(root);
			}
			i++;
		}
	}
	else
	{
		printf("list already created ");
		return;
	}
	return root;
}
Пример #2
0
//Main starts here
void main(){
int n,i,num;


  printf("Enter No. of nodes");
  scanf("%d",&n);
  for(i=1;i<=n;i++)
  { printf("Enter %dst node data ",i);
	 scanf("%d",&num);
	 if(!insertatend(num)){
		 printf("Memory error"); break;}

	 }

	 //prints list
    printlist();
}
Пример #3
0
main()
{
	struct node *root=NULL;
	int choice,val,m,n;
	printf("Menu\n1.create\n2.insertatbegin\n3.insertatend\n4.insertatposition\n5.indexelement\n6.display\n7.exit\n");
	printf("8.deleteatbegin\n9.deleteatend\n10.deleteatpos\n11.m reverse n leave\n");
	while(1)
	{
		printf("\nenter ur choice\n");
		scanf("%d",&choice);
		if(choice<1)
		{
			printf("are u mad ??? enter the correct input ... if u repeat this , I will kick u off");
			
		}
		else {

		switch (choice)
		{
		case 1:
			root=create(root);
			break;
		case 2:
			root=insertatbegin(root);
			break;
		case 3:
			root=insertatend(root);
			break;
		case 4:
			insertatpos(root);
			break;
		case 5:
			indexelement(root);
			break;
		case 6:
			display(root);
			break;
		case 7:
			exit(1);
		case 8:
			root=deleteatbeg(root);
			break;
		case 9:
			root=deleteatend(root);
			break;
		case 10:
			root=deleteatpos(root);
			break;
		case 11:
			printf("enter no of nodes to be reverse");
			scanf("%d",&m);
			printf("enter no of nodes to be leave ");
			scanf("%d",&n);
			root=mreversenleave(root,m,n);
			 	break;

		}
		}
	}

	getch();

}