Chinaunix首页 | 论坛 | 博客
  • 博客访问: 134136
  • 博文数量: 20
  • 博客积分: 128
  • 博客等级: 入伍新兵
  • 技术积分: 310
  • 用 户 组: 普通用户
  • 注册时间: 2012-12-10 18:16
文章分类

全部博文(20)

文章存档

2013年(15)

2012年(5)

分类: Windows平台

2013-08-28 20:05:50

#include
#include
#include

typedef enum sk_error_code_e
{
SK_APP_LIST_SUCCESS = 0,
SK_APP_LIST_FAILD
}sk_error_code_t;



typedef char DATA;

typedef struct node
{
DATA  data;
struct node *next;
}list;

int sk_app_list_create(struct node *sk_app_list_head);
int sk_app_list_delete(struct node *sk_app_list_head,DATA data);
int sk_app_list_print(struct node *sk_app_list_head);
int sk_app_list_search(struct node *sk_app_list_head,DATA data);
int sk_app_list_add(struct node *sk_app_list_head,DATA data_find,DATA data_add);
int sk_app_list_revese(struct node *sk_app_list_head);

int sk_app_list_revese(struct node *sk_app_list_head)
{
list *p_list_pre = sk_app_list_head->next;
list *p_list_cur = NULL;
list *p_list_next = NULL;
sk_app_list_head->next = NULL;
while(p_list_pre != NULL)
{
p_list_cur = p_list_pre->next;
p_list_pre->next = p_list_next;
p_list_next = p_list_pre;
p_list_pre = p_list_cur;
}
sk_app_list_head->next = p_list_next;
return SK_APP_LIST_SUCCESS;
}


int sk_app_list_add(struct node *sk_app_list_head,DATA data_find,DATA data_add)
{
list *p_list_p = sk_app_list_head->next;
list *p_list_new;

while(p_list_p != NULL)

if(p_list_p->data == data_find)
break;
p_list_p = p_list_p->next;
}
if(p_list_p == NULL)
{
printf("didn't find the data\n");
return SK_APP_LIST_FAILD;
}
p_list_new = (struct node *)malloc(sizeof(struct node));
if(p_list_new == NULL)
{
return SK_APP_LIST_FAILD;
}
p_list_new->data = data_add;
p_list_new->next = p_list_p->next; 
p_list_p->next = p_list_new;


return SK_APP_LIST_SUCCESS;
}


int sk_app_list_search(struct node *sk_app_list_head,DATA data)
{
list *p_list_p = sk_app_list_head->next;


while(p_list_p != NULL)

if(p_list_p->data == data)
break;
p_list_p = p_list_p->next;
}
if(p_list_p == NULL)
{
printf("didn't find the data\n");
return SK_APP_LIST_FAILD;
}
return SK_APP_LIST_SUCCESS;


}


int sk_app_list_delete(struct node *sk_app_list_head,DATA data)
{
list *p_list_del;
list *p_list_p;


p_list_del = sk_app_list_head->next;
    p_list_p = sk_app_list_head;
while(p_list_del != NULL )
{
if(p_list_del->data == data)
break;
p_list_p = p_list_del;
p_list_del = p_list_del->next;

}
if(p_list_del == NULL)
{
printf("didn't find the data\n");
return SK_APP_LIST_FAILD;
}
p_list_p->next = p_list_del->next;


return SK_APP_LIST_SUCCESS;
}


int sk_app_list_create(struct node *sk_app_list_head)
{
list *p_list_p = NULL;
list *p_list_q = NULL;

p_list_p = (struct node *)malloc(sizeof(struct node));
if(p_list_p == NULL)
{
return SK_APP_LIST_FAILD;
}
p_list_q = p_list_p;
printf("please input the data:\n");
scanf("%c",&(p_list_p->data));
flushall();
while(p_list_p->data != '#')
{
if( sk_app_list_head->next== NULL)
{
sk_app_list_head->next = p_list_p;
}
else
{
p_list_q->next = p_list_p;
}
p_list_q = p_list_p;
p_list_p = (struct node *)malloc(sizeof(struct node));
if(p_list_p == NULL)
{
return SK_APP_LIST_FAILD;
}
scanf("%c",&(p_list_p->data));
flushall();
}
p_list_q->next = NULL;
free(p_list_p);
return SK_APP_LIST_SUCCESS;
}


int sk_app_list_print(struct node *sk_app_list_head)
{
list *p_list_p;


p_list_p = sk_app_list_head->next;
while(p_list_p != NULL)
{
printf("%c",p_list_p->data);
p_list_p = p_list_p->next;
}
return SK_APP_LIST_SUCCESS;
}




int main(void)
{
list *sk_list_head;
DATA data;
DATA data_add;


sk_list_head = (struct node *)malloc(sizeof(struct node));
sk_list_head->next = NULL;
if(sk_list_head == NULL)
{
return SK_APP_LIST_FAILD;
}
sk_app_list_create(sk_list_head);
sk_app_list_print(sk_list_head);
printf("please input which data you want to find :\n");
scanf("%c",&data);
flushall();
if(sk_app_list_search(sk_list_head,data) == SK_APP_LIST_SUCCESS)
{
printf("find it!\n");
}
printf("please input which data you want to  delete:\n");
scanf("%c",&data);
flushall();
sk_app_list_delete(sk_list_head,data);
sk_app_list_print(sk_list_head);
printf("please input which data you want to  add and where you want to put it :\n");
scanf("%c",&data_add);
flushall();
scanf("%c",&data);
flushall();
    sk_app_list_add(sk_list_head, data, data_add);
sk_app_list_print(sk_list_head);
    printf("link reverse!\n");
sk_app_list_revese(sk_list_head);
sk_app_list_print(sk_list_head);


return SK_APP_LIST_SUCCESS;
}




sk_app_list_head->next = NULL;
while(p_list_pre != NULL)
{
p_list_cur = p_list_pre->next;
p_list_pre->next = p_list_next;
p_list_next = p_list_pre;
p_list_pre = p_list_cur;
}
sk_app_list_head->next = p_list_next;
return SK_APP_LIST_SUCCESS;
}

int sk_app_list_add(struct node *sk_app_list_head,DATA data_find,DATA data_add)
{
list *p_list_p = sk_app_list_head->next;
list *p_list_new;
while(p_list_p != NULL)

if(p_list_p->data == data_find)
break;
p_list_p = p_list_p->next;
}
if(p_list_p == NULL)
{
printf("didn't find the data\n");
return SK_APP_LIST_FAILD;
}
p_list_new = (struct node *)malloc(sizeof(struct node));
if(p_list_new == NULL)
{
return SK_APP_LIST_FAILD;
}
p_list_new->data = data_add;
p_list_new->next = p_list_p->next; 
p_list_p->next = p_list_new;


return SK_APP_LIST_SUCCESS;
}


int sk_app_list_search(struct node *sk_app_list_head,DATA data)
{
list *p_list_p = sk_app_list_head->next;


while(p_list_p != NULL)

if(p_list_p->data == data)
break;
p_list_p = p_list_p->next;
}
if(p_list_p == NULL)
{
printf("didn't find the data\n");
return SK_APP_LIST_FAILD;
}
return SK_APP_LIST_SUCCESS;


}


int sk_app_list_delete(struct node *sk_app_list_head,DATA data)
{
list *p_list_del;
list *p_list_p;


p_list_del = sk_app_list_head->next;
    p_list_p = sk_app_list_head;
while(p_list_del != NULL )
{
if(p_list_del->data == data)
break;
p_list_p = p_list_del;
p_list_del = p_list_del->next;

}
if(p_list_del == NULL)
{
printf("didn't find the data\n");
return SK_APP_LIST_FAILD;
}
p_list_p->next = p_list_del->next;


return SK_APP_LIST_SUCCESS;
}


int sk_app_list_create(struct node *sk_app_list_head)
{
list *p_list_p = NULL;
list *p_list_q = NULL;

p_list_p = (struct node *)malloc(sizeof(struct node));
if(p_list_p == NULL)
{
return SK_APP_LIST_FAILD;
}
p_list_q = p_list_p;
printf("please input the data:\n");
scanf("%c",&(p_list_p->data));
flushall();
while(p_list_p->data != '#')
{
if( sk_app_list_head->next== NULL)
{
sk_app_list_head->next = p_list_p;
}
else
{
p_list_q->next = p_list_p;
}
p_list_q = p_list_p;
p_list_p = (struct node *)malloc(sizeof(struct node));
if(p_list_p == NULL)
{
return SK_APP_LIST_FAILD;
}
scanf("%c",&(p_list_p->data));
flushall();
}
p_list_q->next = NULL;
free(p_list_p);
return SK_APP_LIST_SUCCESS;
}


int sk_app_list_print(struct node *sk_app_list_head)
{
list *p_list_p;


p_list_p = sk_app_list_head->next;
while(p_list_p != NULL)
{
printf("%c",p_list_p->data);
p_list_p = p_list_p->next;
}
return SK_APP_LIST_SUCCESS;
}




int main(void)
{
list *sk_list_head;
DATA data;
DATA data_add;


sk_list_head = (struct node *)malloc(sizeof(struct node));
sk_list_head->next = NULL;
if(sk_list_head == NULL)
{
return SK_APP_LIST_FAILD;
}
sk_app_list_create(sk_list_head);
sk_app_list_print(sk_list_head);
printf("please input which data you want to find :\n");
scanf("%c",&data);
flushall();
if(sk_app_list_search(sk_list_head,data) == SK_APP_LIST_SUCCESS)
{
printf("find it!\n");
}
printf("please input which data you want to  delete:\n");
scanf("%c",&data);
flushall();
sk_app_list_delete(sk_list_head,data);
sk_app_list_print(sk_list_head);
printf("please input which data you want to  add and where you want to put it :\n");
scanf("%c",&data_add);
flushall();
scanf("%c",&data);
flushall();
    sk_app_list_add(sk_list_head, data, data_add);
sk_app_list_print(sk_list_head);
    printf("link reverse!\n");
sk_app_list_revese(sk_list_head);
sk_app_list_print(sk_list_head);


return SK_APP_LIST_SUCCESS;
}




while(p_list_p != NULL)

if(p_list_p->data == data_find)
break;
p_list_p = p_list_p->next;
}
if(p_list_p == NULL)
{
printf("didn't find the data\n");
return SK_APP_LIST_FAILD;
}
p_list_new = (struct node *)malloc(sizeof(struct node));
if(p_list_new == NULL)
{
return SK_APP_LIST_FAILD;
}
p_list_new->data = data_add;
p_list_new->next = p_list_p->next; 
p_list_p->next = p_list_new;

return SK_APP_LIST_SUCCESS;
}

int sk_app_list_search(struct node *sk_app_list_head,DATA data)
{
list *p_list_p = sk_app_list_head->next;

while(p_list_p != NULL)

if(p_list_p->data == data)
break;
p_list_p = p_list_p->next;
}
if(p_list_p == NULL)
{
printf("didn't find the data\n");
return SK_APP_LIST_FAILD;
}
return SK_APP_LIST_SUCCESS;

}

int sk_app_list_delete(struct node *sk_app_list_head,DATA data)
{
list *p_list_del;
list *p_list_p;

p_list_del = sk_app_list_head->next;
    p_list_p = sk_app_list_head;
while(p_list_del != NULL )
{
if(p_list_del->data == data)
break;
p_list_p = p_list_del;
p_list_del = p_list_del->next;
}
if(p_list_del == NULL)
{
printf("didn't find the data\n");
return SK_APP_LIST_FAILD;
}
p_list_p->next = p_list_del->next;


return SK_APP_LIST_SUCCESS;
}


int sk_app_list_create(struct node *sk_app_list_head)
{
list *p_list_p = NULL;
list *p_list_q = NULL;

p_list_p = (struct node *)malloc(sizeof(struct node));
if(p_list_p == NULL)
{
return SK_APP_LIST_FAILD;
}
p_list_q = p_list_p;
printf("please input the data:\n");
scanf("%c",&(p_list_p->data));
flushall();
while(p_list_p->data != '#')
{
if( sk_app_list_head->next== NULL)
{
sk_app_list_head->next = p_list_p;
}
else
{
p_list_q->next = p_list_p;
}
p_list_q = p_list_p;
p_list_p = (struct node *)malloc(sizeof(struct node));
if(p_list_p == NULL)
{
return SK_APP_LIST_FAILD;
}
scanf("%c",&(p_list_p->data));
flushall();
}
p_list_q->next = NULL;
free(p_list_p);
return SK_APP_LIST_SUCCESS;
}


int sk_app_list_print(struct node *sk_app_list_head)
{
list *p_list_p;


p_list_p = sk_app_list_head->next;
while(p_list_p != NULL)
{
printf("%c",p_list_p->data);
p_list_p = p_list_p->next;
}
return SK_APP_LIST_SUCCESS;
}




int main(void)
{
list *sk_list_head;
DATA data;
DATA data_add;


sk_list_head = (struct node *)malloc(sizeof(struct node));
sk_list_head->next = NULL;
if(sk_list_head == NULL)
{
return SK_APP_LIST_FAILD;
}
sk_app_list_create(sk_list_head);
sk_app_list_print(sk_list_head);
printf("please input which data you want to find :\n");
scanf("%c",&data);
flushall();
if(sk_app_list_search(sk_list_head,data) == SK_APP_LIST_SUCCESS)
{
printf("find it!\n");
}
printf("please input which data you want to  delete:\n");
scanf("%c",&data);
flushall();
sk_app_list_delete(sk_list_head,data);
sk_app_list_print(sk_list_head);
printf("please input which data you want to  add and where you want to put it :\n");
scanf("%c",&data_add);
flushall();
scanf("%c",&data);
flushall();
    sk_app_list_add(sk_list_head, data, data_add);
sk_app_list_print(sk_list_head);
    printf("link reverse!\n");
sk_app_list_revese(sk_list_head);
sk_app_list_print(sk_list_head);


return SK_APP_LIST_SUCCESS;
}




}
if(p_list_del == NULL)
{
printf("didn't find the data\n");
return SK_APP_LIST_FAILD;
}
p_list_p->next = p_list_del->next;

return SK_APP_LIST_SUCCESS;
}

int sk_app_list_create(struct node *sk_app_list_head)
{
list *p_list_p = NULL;
list *p_list_q = NULL;
p_list_p = (struct node *)malloc(sizeof(struct node));
if(p_list_p == NULL)
{
return SK_APP_LIST_FAILD;
}
p_list_q = p_list_p;
printf("please input the data:\n");
scanf("%c",&(p_list_p->data));
flushall();
while(p_list_p->data != '#')
{
if( sk_app_list_head->next== NULL)
{
sk_app_list_head->next = p_list_p;
}
else
{
p_list_q->next = p_list_p;
}
p_list_q = p_list_p;
p_list_p = (struct node *)malloc(sizeof(struct node));
if(p_list_p == NULL)
{
return SK_APP_LIST_FAILD;
}
scanf("%c",&(p_list_p->data));
flushall();
}
p_list_q->next = NULL;
free(p_list_p);
return SK_APP_LIST_SUCCESS;
}


int sk_app_list_print(struct node *sk_app_list_head)
{
list *p_list_p;


p_list_p = sk_app_list_head->next;
while(p_list_p != NULL)
{
printf("%c",p_list_p->data);
p_list_p = p_list_p->next;
}
return SK_APP_LIST_SUCCESS;
}




int main(void)
{
list *sk_list_head;
DATA data;
DATA data_add;


sk_list_head = (struct node *)malloc(sizeof(struct node));
sk_list_head->next = NULL;
if(sk_list_head == NULL)
{
return SK_APP_LIST_FAILD;
}
sk_app_list_create(sk_list_head);
sk_app_list_print(sk_list_head);
printf("please input which data you want to find :\n");
scanf("%c",&data);
flushall();
if(sk_app_list_search(sk_list_head,data) == SK_APP_LIST_SUCCESS)
{
printf("find it!\n");
}
printf("please input which data you want to  delete:\n");
scanf("%c",&data);
flushall();
sk_app_list_delete(sk_list_head,data);
sk_app_list_print(sk_list_head);
printf("please input which data you want to  add and where you want to put it :\n");
scanf("%c",&data_add);
flushall();
scanf("%c",&data);
flushall();
    sk_app_list_add(sk_list_head, data, data_add);
sk_app_list_print(sk_list_head);
    printf("link reverse!\n");
sk_app_list_revese(sk_list_head);
sk_app_list_print(sk_list_head);


return SK_APP_LIST_SUCCESS;
}




p_list_p = (struct node *)malloc(sizeof(struct node));
if(p_list_p == NULL)
{
return SK_APP_LIST_FAILD;
}
p_list_q = p_list_p;
printf("please input the data:\n");
scanf("%c",&(p_list_p->data));
flushall();
while(p_list_p->data != '#')
{
if( sk_app_list_head->next== NULL)
{
sk_app_list_head->next = p_list_p;
}
else
{
p_list_q->next = p_list_p;
}
p_list_q = p_list_p;
p_list_p = (struct node *)malloc(sizeof(struct node));
if(p_list_p == NULL)
{
return SK_APP_LIST_FAILD;
}
scanf("%c",&(p_list_p->data));
flushall();
}
p_list_q->next = NULL;
free(p_list_p);
return SK_APP_LIST_SUCCESS;
}

int sk_app_list_print(struct node *sk_app_list_head)
{
list *p_list_p;

p_list_p = sk_app_list_head->next;
while(p_list_p != NULL)
{
printf("%c",p_list_p->data);
p_list_p = p_list_p->next;
}
return SK_APP_LIST_SUCCESS;
}



int main(void)
{
list *sk_list_head;
DATA data;
DATA data_add;

sk_list_head = (struct node *)malloc(sizeof(struct node));
sk_list_head->next = NULL;
if(sk_list_head == NULL)
{
return SK_APP_LIST_FAILD;
}
sk_app_list_create(sk_list_head);
sk_app_list_print(sk_list_head);
printf("please input which data you want to find :\n");
scanf("%c",&data);
flushall();
if(sk_app_list_search(sk_list_head,data) == SK_APP_LIST_SUCCESS)
{
printf("find it!\n");
}
printf("please input which data you want to  delete:\n");
scanf("%c",&data);
flushall();
sk_app_list_delete(sk_list_head,data);
sk_app_list_print(sk_list_head);
printf("please input which data you want to  add and where you want to put it :\n");
scanf("%c",&data_add);
flushall();
scanf("%c",&data);
flushall();
    sk_app_list_add(sk_list_head, data, data_add);
sk_app_list_print(sk_list_head);
    printf("link reverse!\n");
sk_app_list_revese(sk_list_head);
sk_app_list_print(sk_list_head);

return SK_APP_LIST_SUCCESS;
}


阅读(1770) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~