显示标签为“Job”的博文。显示所有博文
显示标签为“Job”的博文。显示所有博文

2012年8月17日星期五

项目

项目是解决什么问题的?
为什么会有这样的问题存在?
如果不解决,对用户有什么影响?
这种问题如何解决?
为什么要这样解决?
有其他更快的解决方案么?
采用的方案比别的方案好在哪里?
这个方案执行存在什么困难?这个困难如何解决?

问题的解决

描述问题
该问题的优先级/风险等级
问题的负责人
该问题的当前处理状态
解决该问题的日期

2008年10月17日星期五

队列:节点插入,节点删除,测长,建立

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

typedef struct node_x {
   int data;

   struct node_x *next;
}qnode;

typedef struct queue_x {
   qnode *head;
   qnode *rear;
}queue;


void print_queue(queue *q)
{
   printf("the queue:\n");
   qnode *p = q->head;

   while (p) {
       printf("%d ", p->data);
       p = p->next;
   }

   printf("\n");
}

int length_queue(queue *q)
{
   int len = 0;
   qnode *p = q->head;

   while (p) {
       len++;
       p = p->next;
   }

   return len;
}

int delete_qnode(queue *q)
{
   qnode *p;
   int data;

   if (!q->head)
       return;

   data = q->head->data;

   p = q->head->next;

   free(q->head);

   q->head = p;

   if (!p) q->rear = NULL;

   return data;
}

void insert_qnode(queue *q, int data)
{
   qnode *p, *s;

   s = (qnode*)malloc(sizeof(qnode));
   s->data = data;
   s->next = NULL;

   if (!q->rear) {
       q->head = s;

   } else {
       q->rear->next = s;
   }

   q->rear = s;
}

queue * creat_queue(void)
{
   queue *q;
   q = (queue *)malloc(sizeof(queue));
   q->head = NULL;
   q->rear = NULL;
   int data;

   while (1) {
       printf("insert a num:");
       scanf("%d", &data);

       if (data == 0) break;

       insert_qnode(q, data);
   }

   return q;
}

int main(void)
{
   printf("creat a queue:\n");
   queue *q = creat_queue();
   print_queue(q);

   printf("queue length:%d\n", length_queue(q));

   printf("delete a qnode :\n");
   delete_qnode(q);
   print_queue(q);

   printf("insert a qnode 3:\n");
   insert_qnode(q, 3);
   print_queue(q);

   return 0;
} 

2008年10月16日星期四

单链表:打印,测长,建立,节点插入,节点删除,逆置

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

typedef struct link { 
    int data; 

    struct link *next; 
}node; 

void print_link(node *head) 
{ 
    printf("the link:\n"); 

    while (head) { 
        printf("%d ", head->data); 
        head = head->next; 
    } 

    printf("\n"); 
} 

int length_link(node *head) 
{ 
    int len = 0; 

    while (head) { 
        len++; 
        head = head->next; 
    } 

    return len; 
} 

node * delete_node(node *head, int data) 
{ 
    node *p, *q; 

    if (!head) 
        return head; 

    p = head; 

    if (head->data == data) { 
        head = head->next; 
        free(p); 
        return head; 
    } 

    while (p->next) { 
        q = p->next; 

        if (q->data == data) { 
            p->next = q->next; 
            free(q); 
            return head; 
        } 

        p = q; 
    } 

    return head; 
} 

node *insert_node(node *head, int data) 
{ 
    node *p, *s, *q; 

    s = (node*)malloc(sizeof(node)); 
    s->data = data; 

    if (!head) { 
        head = s; 
        head->next = NULL; 
        return head; 
    } 

    p = head; 

    q = NULL; 

    while (p && data >= p->data) { 
        q = p; 
        p = p->next; 
    } 

    if (!q) { 
        s->next = head; 
        head = s; 

    } else { 
        q->next = s; 
        s->next = p; 
    } 

    return head; 
} 

node * creat_link(void) 
{ 
    node *head = NULL; 
    int data; 

    while (1) { 
        printf("insert a num:"); 
        scanf("%d", &data); 

        if (data == 0) break; 

        head = insert_node(head, data); 
    } 

    return head; 
} 

node * reverse_link(node *head) 
{ 
    node *p, *q, *r; 

    if (!head || !head->next) 
        return head; 

    p = head; 

    q = head->next; 

    while (q) { 
        r = q->next; 
        q->next = p; 
        p = q; 
        q = r; 
    } 

    head->next = NULL; 

    return p; 
} 

int main(void) 
{ 
    printf("creat a link:\n"); 
    node *head = creat_link(); 
    print_link(head); 

    printf("link length:%d\n", length_link(head)); 

    printf("delete a node 3:\n"); 
    head = delete_node(head, 3); 
    print_link(head); 

    printf("insert a node 3:\n"); 
    head = insert_node(head, 3); 
    print_link(head); 

    printf("reverse link:\n"); 
    head = reverse_link(head); 
    print_link(head); 

    return 0; 
}