Ejemplo n.º 1
0
 void newEnd(D member) {
     if(head == nullptr)
         newHead(member);
     //Bryn refactor
     else {
         add_after(end);
         end = end->next;
     }
 }
Ejemplo n.º 2
0
Archivo: var.c Proyecto: hjqqq/cvne
struct Var* set_var(struct Item* list, char* name, int value)
{
	struct Var* var = get_var(list, name);
	if(!var)
	{
		var = malloc(sizeof(struct Var));
		strcpy(var->name, name);
		add_after(list, var);
	}
	var->value = value;
	return var;
}
Ejemplo n.º 3
0
int main()
{	
	int i,num,data1;	
	struct node *head=NULL;
	
	while(5 != i)
	{
		printf("\n Linked List");
		printf("\n 1.Append \n 2.Add after \n 3.delete \n 4.Display \n 5.Exit");
		printf("\n Enter your choice :");
		scanf("%d", &i);
		switch(i)
		{
			case 1:	printf("\n Enter a number to append the Linked list ");
				scanf("%d",&num);
				head = append(head,num);
				break;

			case 2: printf("\n Add after which node enter the data vaule");
				scanf("%d",&data1);
				printf("\n Enter the number to add after %d ",data1);
				scanf("%d",&num);	
				head = add_after(head,data1,num);
				break;
	
			case 3: printf("\n Enter the data value to be deleted");
				scanf("%d",&data1);
				head = delete_node(head,data1);
				break;
				
			case 4: printf("\n Displaying the list");
				display(head);
				break;

			case 5: printf("\n Exiting the linked list");
				free_memory(head);
				break;

			default : printf("\n Invalid choice");
				break;
		}
		
		
	}
	printf("\n  \n \n \n \n");

	
return 0;
}
Ejemplo n.º 4
0
int
node_create_after(struct linked_list *list, int data, int newdata)
{
	struct linked_node *newnode;
	struct linked_node *node = get_node(list, data);
	if (!node)
		return -NDNULL;

	newnode = linked_node_alloc_init(newdata);
	if (newnode == NULL)
		return -ENOMEM;

	add_after(node, newnode);
	return 0;
}
Ejemplo n.º 5
0
int main(){

    node *head = NULL;
    push_back(&head, 1);
    push_back(&head, 2);
    push_back(&head, 3);

    node *target = find_node_by_key(&head, 3);
    add_after(&head,&target, 10);


    print_list(&head);
    print_list_reverse(&head);
    return 0;
}
Ejemplo n.º 6
0
/* MAIN PROGRAM */
int main()
{
	Node_ptr my_list = NULL;

	assign_list(my_list);

	cout << "\nTHE LIST IS NOW:\n";
	print_list(my_list);

	cout << "forwards: ";
	print_forwards(my_list);
	cout << endl;

	cout << "backwards: ";
	print_backwards(my_list);
	cout << endl;

	char word[20], lookfor[20];

	cout << endl << "word to insert: ";
	cin.getline(word,20);

	cout << endl << "to be inserted after (' ' for right at beginning): ";
	cin.getline(lookfor,20);

	add_after(my_list, lookfor, word);

	cout << endl << "\nTHE LIST IS NOW:\n";
	print_list(my_list);

	cout << endl << "word to delete: ";
	cin.getline(word,20);

	delete_node(my_list, word);

	cout << endl << "\nTHE LIST IS NOW:\n";
	print_list(my_list);

	return 0;
}
Ejemplo n.º 7
0
int main(void)
{
	/* One structure used in the program */
	struct node llist;
	int rc,i;

	printf("\nAdding at the start of the list...");

	rc = add_at_start(&llist,53);
	if(rc)
	{
		printf("\nAdding at the start of the list not successful...");
		exit(0);
	}
	printf("\nAdding at the start of the list successful...");

	printf("\nDisplaying the list...");
	rc = display_ll(&llist);

	printf("\nAdding at the end...");
	rc = add_at_end(&llist,103);

	printf("\nDisplaying the list...");
	rc = display_ll(&llist);

	printf("\nModifying the start of the list...");
	rc = modify_at_start(&llist,43);

	printf("\nDisplaying the list...");
	rc = display_ll(&llist);

	printf("\nModifying the end of the list...");
	rc = modify_at_end(&llist,203);

	for(i=0;i<5;i++)
	{
		rc = add_at_end(&llist,(i+99));
	}
	
	printf("\nDisplaying the list...");
	rc = display_ll(&llist);
	
	for(i=0;i<3;i++)
	{
		rc = add_at_end(&llist,(i+150));
	}

	printf("\nDisplaying the list...");
	rc = display_ll(&llist);
	
	printf("\nInserting after node 3...");
	rc = add_after(&llist,3,504);
	
	printf("\nDisplaying the list...");
	rc = display_ll(&llist);
	
	printf("\nModifying node 4...");
	rc = modify_node(&llist,4,555);
	
	printf("\nDisplaying the list...");
	rc = display_ll(&llist);

	printf("\nDeleting Node 5...");
	rc = delete_node(&llist,5);

	printf("\nDisplaying the list...");
	rc = display_ll(&llist);

	for(i=0;i<3;i++)
	{
		rc = add_at_end(&llist,(i+342));
	}
	
	printf("\nDisplaying the list...");
	rc = display_ll(&llist);
	
	printf("\nInserting after node 1...");
	rc = add_after(&llist,1,35);
	
	printf("\nDisplaying the list...");
	rc = display_ll(&llist);

	printf("\n\n");

	return 0;
}
Ejemplo n.º 8
0
Archivo: list.c Proyecto: mabm/42sh
void		add_to_end(t_list *list, char *str)
{
  while (list->next != NULL)
    list = list->next;
  add_after(list, str);
}