#job 60 链表的插入与删除


#include <stdio.h>
#include <stdlib.h>

struct s_list
{
	char c ;
	struct s_list *next;

};

void creat_list(struct s_list **headp)
{
	char ch;
	struct s_list * loc_head = NULL,*tail;
	if((ch = getchar()) == '\n');
	else
	{
		loc_head = (struct s_list *)malloc(sizeof(struct s_list));
		loc_head -> c = ch;
		tail = loc_head;
		while((ch = getchar()) != '\n')
		{
			tail -> next = (struct s_list *)malloc(sizeof(struct s_list));
			tail = tail -> next;
			tail -> c = ch;
		}
		tail -> next = NULL;
	}
	*headp = loc_head ;
}

void print_list(struct s_list *headp)
{
	while(headp != NULL)
	{
		printf("%c",headp->c );
		headp = headp -> next;
	}
	printf("\n");
}

void operate_list(struct s_list *headp)
{
	char ch,ch_tmp;
	int flag = 1;
	while((ch = getchar()) != '\n')
	{
	    struct s_list *current = headp ;
		while(current != NULL)
		{
			if(current->c == ch)          //delete note
			{
				struct s_list *tmp=headp;
				flag = 0;
				if(current==headp)
				{
					headp = headp->next;
					print_list(headp);
					break;
				}
				else
				{
					while(tmp->next != current)
					{
						tmp = tmp->next;
					}
					tmp->next = current->next;
					print_list(headp);
					break;
				}
			}
			else
				current = current -> next;

		}
		if(current == NULL)
		{
			struct s_list *tmpp = headp ;
            ch_tmp = tmpp->c;
            while(tmpp != NULL)
		    {
                tmpp = tmpp->next;
                if(tmpp != NULL)
                	if((ch_tmp - (tmpp->c)) < 0)
                	{
                    	ch_tmp = tmpp->c;
                	}
            }
            struct s_list *tmp=headp;
            while(tmp != NULL)
		    {
                if(tmp->c==ch_tmp)
                	break;
                else
                {
                	tmp = tmp -> next;
                }
            }
            struct s_list *loc_head=headp,*after = NULL;

            while(tmp != loc_head)
           	{
           		loc_head = loc_head->next;
            }
            after=loc_head->next;
            struct s_list *tmp0=NULL;
            tmp0 = (struct s_list *)malloc(sizeof(struct s_list));
            tmp0->c=ch;
            tmp0->next=after;
            loc_head->next=tmp0;
            print_list(headp);
		}
		current=headp;
	}
}
int main()
{
	struct s_list *head = NULL;
	creat_list(&head);
	print_list(head);
	operate_list(head);
	return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值