• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            天之道

            享受編程的樂(lè)趣。
            posts - 118, comments - 7, trackbacks - 0, articles - 0
              C++博客 :: 首頁(yè) :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理


            //靜態(tài)順序表的各種操作
            #include<stdio.h>
            #define MaxSize 10
            void insertElem(int Sqlist[],int *len,int i,int x)//表首地址、表長(zhǎng)、插入元素位置、待插入的元素值
            {
                
            int t,temp;
                
            if(*len==MaxSize||i<1||i>*len+1)
                {
                    printf(
            "This insert is illegal\n");
                    
            return;
                }
                
            for(t=*len-1;t>=i-1;t--)
                    Sqlist[t
            +1]=Sqlist[t];//i-1后的元素都向后移一位
                Sqlist[i-1]=x;//插入元素
                *len=*len+1;//表長(zhǎng)加1
            }

            void DelElem(int Sqlist[],int *len,int i)//向順序表中刪除元素
            {
                
            int j;
                
            if(i<1||i>*len)
                {
                    printf(
            "This insert is illegal");
                    
            return;
                }
                
            for(j=i;j<=*len-1;j++)
                    Sqlist[j
            -1]=Sqlist[j];//將第i個(gè)元素之后的元素前移,覆蓋即刪除
                *len=*len-1;
            }

            int main()
            {
                
            int Sqlist[MaxSize];
                
            int len;
                
            int i;
                
            for(i=0;i<6;i++)
                    scanf(
            "%d",&Sqlist[i]);
                len
            =6;
                
            for(i=0;i<len;i++)
                    printf(
            "%d ",Sqlist[i]);
                printf(
            "\nThe spare length is %d\n",MaxSize-len);//顯示表中剩余空間
                insertElem(Sqlist,&len,3,0);//在表中第3個(gè)位置插入整數(shù)0
                for(i=0;i<len;i++)
                    printf(
            "%d ",Sqlist[i]);
                printf(
            "\nThe spare length is %d\n",MaxSize-len);
                insertElem(Sqlist,
            &len,11,0);
                DelElem(Sqlist,
            &len,6);
                
            for(i=0;i<len;i++)
                    printf(
            "%d ",Sqlist[i]);
                printf(
            "\nThe spare length is %d\n",MaxSize-len);
                
            return 0;
            }

            posted @ 2012-03-01 00:53 hoshelly 閱讀(230) | 評(píng)論 (0)編輯 收藏

            #include<stdio.h> //使用數(shù)組創(chuàng)建隊(duì)列
            #define MAXQUEUE 10    //隊(duì)列的最大容量
            int queue[MAXQUEUE]; //隊(duì)列的數(shù)組聲明
            int front=-1;//隊(duì)列的隊(duì)頭
            int rear=-1; //隊(duì)列的隊(duì)尾
            //隊(duì)列數(shù)據(jù)的存入
            int enqueue(int value)
            {
            if(rear>=MAXQUEUE)
            return -1; //檢查隊(duì)列是否全滿
            rear++; //隊(duì)尾指針往前移
            queue[rear]=value; //存入隊(duì)列
            }
            //隊(duì)列數(shù)據(jù)的取出,取出時(shí)隊(duì)頭指針往后移
            int dequeue()
            {
            if(front==rear) //檢查隊(duì)列是否是空
            return -1;  //無(wú)法取出
            front++; //隊(duì)頭指針往前移(即向隊(duì)尾指針?lè)较蛞疲?/div>
            return queue[front]; //隊(duì)列取出
            }
            //主程序:模擬隊(duì)列操作
            //輸出輸入的內(nèi)容都會(huì)存儲(chǔ)在數(shù)組中,接著輸出數(shù)組內(nèi)容來(lái)看其結(jié)果
            void main()
            {
            int input[100];//存儲(chǔ)輸入的元素
            int output[100];//存儲(chǔ)取出的元素
            int select;
            int i_count=0; //數(shù)組input的索引
            int o_count=0;
            int loop=1;
            int i,temp;
            while(loop)
            {
            printf("[1]輸入 [2]取出 [3]列出全部?jī)?nèi)容 ==>");
            scanf("%d",&select);
            switch(select)
            {
            case 1:printf("請(qǐng)輸入存入隊(duì)列的值(%d)==> ",i_count+1);
               scanf("%d",&temp);
               if(enqueue(temp) == -1)
               printf("隊(duì)列全滿.\n");
               else
               input[i_count++]=temp;
               break;
            case 2:if((temp=dequeue())==-1)
               printf("隊(duì)列是空的.\n");
               else
               {
               printf("取出隊(duì)列元素:%d\n",temp);
               output[o_count++]=temp;
               }
               break;
            case 3: loop=0;
                break;
            }
            }
            printf("輸入隊(duì)列的元素:");
            for(i=0;i<i_count;i++)
            printf("[%d]",input[i]);
            printf("\n取出隊(duì)列的元素: ");
            for(i=0;i<o_count;i++)
            printf("[%d]",output[i]);
            printf("\n剩下隊(duì)列的元素:");
            while((temp=dequeue())!=-1)
            printf("[%d]",temp);
            printf("\n");
            }

            posted @ 2012-02-28 00:38 hoshelly 閱讀(368) | 評(píng)論 (0)編輯 收藏

            //利用鏈表創(chuàng)建棧
            #include<time.h>
            #include<stdlib.h>
            #include<stdio.h>
            struct stack_node
            {
                int data;
            struct stack_node*next;
            };
            typedef struct stack_node stack_list;
            typedef stack_list *link;
            link stack=NULL;
            //棧數(shù)據(jù)的存入
            int push(int value)
            {
               link new_node;
               new_node=(link)malloc(sizeof(stack_list));
               if(!new_node)
               {
                  printf("內(nèi)存分配失敗!\n");
              return -1;
            }
            new_node->data=value;
            new_node->next=stack;
            stack=new_node;
            }
            //棧數(shù)據(jù)的取出
            int pop()
            {
               link top;
               int temp;
               if(stack!=NULL)
               {
                  top=stack;
              stack=stack->next;
              temp=top->data;
              free(top);
              return temp;
            }
            6
                else
            return -1;
            }
            int empty()
            {
               if(stack == NULL)
                return 1;
               else
                return 0;
            }
            void main()
            {
              int card[52];
              int pos;
              int i,temp;
              for(i=0;i<52;i++)
                card[i]=0;
              i=0;
              while(i!=52)
              {
                 pos=rand()%52;
             if(card[pos] == 0)
             {
                push(pos);
            card[pos]=1;
            i++;
             }
              }
              
              printf("  1    2    3    4\n");
              printf("======================\n");
              for(i=0;i<5;i++)
              {
                 temp=pop();
             printf("[%c%2d]",temp/13+3,temp%13+1);
             temp=pop();
             printf("[%c%2d]",temp/13+3,temp%13+1);
             temp=pop();
             printf("[%c%2d]",temp/13+3,temp%13+1);
             temp=pop();
             printf("[%c%2d]",temp/13+3,temp%13+1);
             printf("\n");
               }
            }

            posted @ 2012-02-28 00:37 hoshelly 閱讀(222) | 評(píng)論 (0)編輯 收藏

            //應(yīng)用棧來(lái)走迷宮
            #include<stdio.h>
            #include<stdlib.h>
            struct stack_node
            {
                int x;//路徑坐標(biāo)x
                int y;//路徑坐標(biāo)y
                struct stack_node *next;//指向下一結(jié)點(diǎn)
            };
            typedef struct stack_node stack_list;
            typedef stack_list *link;
            link path=NULL;//路徑棧指針
            //棧數(shù)據(jù)的存入
            link push(link stack,int x,int y)
            {
                link new_node;//新結(jié)點(diǎn)指針
               
            //分配結(jié)點(diǎn)內(nèi)存
                new_node=(link)malloc(sizeof(stack_list));
                if(!new_node)
                {
                    printf("內(nèi)存分配失敗!\n");
                    return NULL;
                }
                new_node->x=x; //存入路徑坐標(biāo)x
                new_node->y=y; //存入路徑坐標(biāo)y
                new_node->next=stack;//新結(jié)點(diǎn)指向原開(kāi)始
                stack=new_node; //新結(jié)點(diǎn)成為棧開(kāi)始
                return stack;
            }
            //棧數(shù)據(jù)的取出
            link pop(link stack,int *x,int *y)
            {
                link top;//指向棧頂端
                if(stack!=NULL)
                {
                    top=stack;
                    stack=stack->next;//棧指針指向下結(jié)點(diǎn)
                    *x=stack->x;//取出路徑坐標(biāo)x
                    *y=stack->y;//取出路徑坐標(biāo)y
                    free(top);
                    return stack;
                }
                else
                    *x=-1;
            }
            //主程序:用回溯的方法在數(shù)組迷宮找出口
            //數(shù)字0:表示是可以走的路
            //數(shù)字1:表示是墻壁,不可走的路
            //數(shù)字2:表示是走過(guò)的路
            //數(shù)字3:表示是回溯的路
            void main()
            {
                int maze[7][10]={
                    1,1,1,1,1,1,1,1,1,1,
                    1,0,1,0,1,0,0,0,0,1,
                    1,0,1,0,1,0,1,1,0,1,
                    1,0,1,0,1,1,1,0,0,1,
                    1,0,1,0,0,0,0,0,1,1,
                    1,0,0,0,1,1,1,0,0,1,
                    1,1,1,1,1,1,1,1,1,1,};
                
                int i,j;
                int x=5;//迷宮入口坐標(biāo)
                int y=8;
                while(x!=1||y!=1)//是否是迷宮出口
                {
                    maze[x][y]=2;//標(biāo)示走過(guò)的路
                    if(maze[x-1][y]<=0) //往上方走
                    {
                        x=x-1;
                        path=push(path,x,y);//存入路徑
                    }
                    else if(maze[x+1][y]<=0)//往下方走
                    {
                            x=x+1;
                            path=push(path,x,y);
                    }
                    else if(maze[x][y-1]<=0)//往左方走
                    {
                        y=y-1;
                        path=push(path,x,y);
                    }
                    else if(maze[x][y+1]<=0)//往右方走
                    {
                        y=y+1;
                        path=push(path,x,y);
                    }
                    else
                    {
                        maze[x][y]=3;
                        path=pop(path,&x,&y);//退回一步
                    }
                }
                maze[x][y]=2;
                printf("迷宮的路徑如下圖所示:\n");
                for(i=1;i<6;i++)//輸出迷宮圖形
                {
                    for(j=1;j<9;j++)
                        printf("%d",maze[i][j]);//輸出各坐標(biāo)
                    printf("\n");
                }
            }
                    

            posted @ 2012-02-28 00:37 hoshelly 閱讀(663) | 評(píng)論 (0)編輯 收藏

            #include<stdlib.h>
            #include<time.h>
            #include<stdio.h>
            #define MAXSTACK 100//棧的最大容量
            int stack[MAXSTACK];//棧的數(shù)組聲明
            int top =-1; //棧的頂端
            //棧的數(shù)據(jù)存入
            int push(int value)
            {
               if(top>=MAXSTACK)//是否超過(guò)容量
               {
                  printf("棧的內(nèi)容全滿\n");
                  return -1;
                }
                top++;
                stack[top]=value;//棧指針加1,存入棧
            }
            //棧數(shù)據(jù)的取出
            int pop()
            {
               int temp;
               if(top<0)
               {
                  printf("棧內(nèi)容是空的\n");
                  return -1;
                }
                temp = stack[top];
                top--;
                return temp;
            }
            //檢查棧是否是空的
            int empty()
            {
              if(top == -1)
              return 1;
              else
              return 0;
             }
             
             //主程序:運(yùn)用empty()檢查牌是否發(fā)完
             
            //紅心:數(shù)組0~12,方塊:數(shù)組13~25,梅花:數(shù)組26~38,黑桃:數(shù)組39~51
             
             void main()
             {
                int card[52];
                int pos;
                int i,temp;
                for(i=0;i<52;i++)
                  card[i]=0;
                i=0;
                while(i!=5)//洗五張牌循環(huán)
                {
                   pos=rand()%52;//隨機(jī)數(shù)取值0~51
                   if(card[pos] == 0) //是否是未洗牌
                   {
                      push(pos);//存此張牌進(jìn)棧
                      card[pos]=1;//設(shè)置此張牌洗過(guò)
                      i++;//下一張牌
                    }
                }
                
                while(!empty())//發(fā)完棧全部的牌
                {
                   temp=pop(); //取出棧數(shù)據(jù)
                   printf("[%c%3d]",temp/13+3,temp%13+1);
                }
                printf("\n");
            }

            posted @ 2012-02-28 00:36 hoshelly 閱讀(198) | 評(píng)論 (0)編輯 收藏

            #include<stdlib.h>
            #include<stdio.h>
            struct dlist  //雙向鏈表結(jié)構(gòu)聲明
            {
               int data;
               struct dlist *front;//指向下一結(jié)點(diǎn)的指針
               struct dlist *back; //指向前一結(jié)點(diǎn)的指針
            };
            typedef struct dlist dnode;//雙向鏈表新類(lèi)型
            typedef dnode *dlink;//雙向鏈表指針新類(lèi)型
            void printdlist(dlink head)
            {
               while (head!=NULL)
               {
                  printf("[%d]",head->data);
              head=head->front;
                }
            printf("\n");
            }
            //雙向鏈表結(jié)點(diǎn)的插入
            dlink insertnode(dlink head,dlink ptr,int value)
            {
               dlink new_node;
               //創(chuàng)建新結(jié)點(diǎn),分配結(jié)點(diǎn)內(nèi)存
               new_node=(dlink)malloc(sizeof(dnode));
               if(!new_node)
               return NULL;
               new_node->data=value;
               new_node->front=NULL;
               new_node->back=NULL;
               
               if(head == NULL)
               return new_node;
               
               if(ptr == NULL)
               {
                   //第一種情況:插在第一個(gè)結(jié)點(diǎn)之前,成為鏈表開(kāi)始
               new_node->front=head;
               head->back=new_node;
               head=new_node;
            }
            else
            {
               if(ptr->front == NULL)
               {
                  //第二種情況:插在鏈表的最后
              ptr->front=new_node;//最后結(jié)點(diǎn)指向新結(jié)點(diǎn)
              new_node->back=ptr;//新結(jié)點(diǎn)指回最后結(jié)點(diǎn)
            }
               else
               {
                  //第三種情況:插入結(jié)點(diǎn)至鏈表中間結(jié)點(diǎn)內(nèi)
              ptr->front->back=new_node;//下一結(jié)點(diǎn)指回新結(jié)點(diǎn)
              new_node->front=ptr->front;//新結(jié)點(diǎn)指向下一結(jié)點(diǎn)
              new_node->back=ptr; //新結(jié)點(diǎn)指回插入結(jié)點(diǎn)
              ptr->front=new_node; //插入結(jié)點(diǎn)指向新結(jié)點(diǎn)
            }
            }
            return head;//返回鏈表起始指針
            }
            //主程序:使用插入結(jié)點(diǎn)的方式來(lái)創(chuàng)建鏈表,完成后將鏈表內(nèi)容輸出
            void main()
            {
               dlink head = NULL;//循環(huán)鏈表指針
               dlink tail = NULL;//鏈表最后的指針
               int list[6]={1,2,3,4,5,6};
               int i;
               head = insertnode(head,head,list[0]);
               printdlist(head);
               tail = head;//保留鏈表最后指針
               //第一種情況:插在第一個(gè)結(jié)點(diǎn)之前
               head=insertnode(head,NULL,list[1]);
               printdlist(head);
               //第二種情況:插在鏈表的最后
               head = insertnode(head,tail,list[2]);
               printdlist(head);
               for(i=3;i<6;i++)
               {
                  //第三種情況:插入結(jié)點(diǎn)至鏈表中間結(jié)點(diǎn)內(nèi)
              head = insertnode(head,head,list[i]);
              printdlist(head);
                }
            }

            posted @ 2012-02-28 00:35 hoshelly 閱讀(632) | 評(píng)論 (0)編輯 收藏

            /*含頭結(jié)點(diǎn)的循環(huán)鏈表的多項(xiàng)式*/
            # include<stdio.h>
            # include<stdlib.h>
            struct plist             /* 多項(xiàng)式結(jié)構(gòu)聲明*/
            {
            int coef;                 /*多項(xiàng)式的系數(shù)*/
            int exp;                  /*多項(xiàng)式的指數(shù)*/
            struct plist *next;       /*指向下一結(jié)點(diǎn)的指針*/
            };
            typedef struct plist pnode; /* 多項(xiàng)式新類(lèi)型*/
            typedef pnode *plink;        /* 多項(xiàng)式指針新類(lèi)型*/
            /*鏈表輸出*/
            void printpoly(plink poly)
            {
            plink ptr;
            ptr=poly->next;       /*指向鏈表開(kāi)始*/
            while(poly!=ptr)      /*鏈表遍歷循環(huán)*/
            {
            /*輸出結(jié)點(diǎn)數(shù)據(jù)*/
            printf("%dX^%d",ptr->coef,ptr->exp);
            ptr=ptr->next;      /* 指向下一結(jié)點(diǎn)*/
            if(poly!=ptr) printf("+");
            }
            printf("\n");       /* 換行*/
            }
            /*使用數(shù)組值創(chuàng)建多項(xiàng)式*/
            plink createpoly(int *array,int len)
            {
            plink head;    /*循環(huán)鏈表的指針*/
            plink before; /*前一結(jié)點(diǎn)的指針*/
            plink new_node;   /*新結(jié)點(diǎn)的指針*/
            int i;
            /*創(chuàng)建頭結(jié)點(diǎn),分配結(jié)點(diǎn)內(nèi)存*/
            head=(plink)malloc(sizeof(pnode));
            if(!head) return NULL; /*檢查內(nèi)存指針*/
            head->exp=-1;           /*創(chuàng)建結(jié)點(diǎn)內(nèi)容*/
            before=head;            /*指向第一個(gè)結(jié)點(diǎn)*/
            for(i=len-1;i>=0;i--)   /*用循環(huán)創(chuàng)建其他結(jié)點(diǎn)*/
            if(array[i]!=0)
            {
            /*分配結(jié)點(diǎn)內(nèi)存*/
            new_node=(plink)malloc(sizeof(pnode));
            if(!new_node) return NULL;    /*檢查內(nèi)存指針*/
            new_node->coef=array[i];      /*創(chuàng)建系數(shù)內(nèi)容*/
            new_node->exp=i;              /*創(chuàng)建指數(shù)內(nèi)容*/
            new_node->next=NULL;          /*設(shè)置指針初值*/
            before->next=new_node;        /*將前結(jié)點(diǎn)指向新結(jié)點(diǎn)*/
            before=new_node;              /*新結(jié)點(diǎn)成為前結(jié)點(diǎn)*/
            }
            new_node->next=head;           /*創(chuàng)建環(huán)狀鏈接*/
            return head;                   /*返回鏈表起始指針*/
            }
            /*多項(xiàng)式相加*/
            plink polyadd(plink poly1,plink poly2)
            {
            plink head1;                 /*多項(xiàng)式1的開(kāi)始*/
            plink head2;                 /*多項(xiàng)式2的開(kāi)始*/
            plink result;                /*多項(xiàng)式的結(jié)果*/
            plink before;                /*前一結(jié)點(diǎn)的指針*/
            plink new_node;              /*新結(jié)點(diǎn)的指針*/
            head1=poly1->next;           /*指向多項(xiàng)式1的開(kāi)始*/
            head2=poly2->next;           /*指向多項(xiàng)式2的開(kāi)始*/
            /*創(chuàng)建頭結(jié)點(diǎn)且分配結(jié)點(diǎn)內(nèi)存*/
            result=(plink)malloc(sizeof(pnode));
            if(!result) return NULL;       /*檢查內(nèi)存指針*/
            result->exp=-1;                /*創(chuàng)建結(jié)點(diǎn)內(nèi)容*/
            before=result;                 /*指向第一個(gè)結(jié)點(diǎn)*/
            while(poly1!=head1||poly2!=head2)
            {
            /*分配結(jié)點(diǎn)內(nèi)存*/
            new_node=(plink)malloc(sizeof(pnode));
            if(!new_node) return NULL; /*檢查內(nèi)存指針*/
            if(head1->exp<head2->exp)      /*多項(xiàng)式2的指數(shù)大*/
            {
            new_node->coef=head2->coef;    /*設(shè)置系數(shù)*/
            new_node->exp=head2->exp;      /*設(shè)置指數(shù)*/
            head2=head2->next;             /*指向下一結(jié)點(diǎn)*/
            }
            else if(head1->exp>head2->exp)      /*多項(xiàng)式1的指數(shù)大*/
               {
               new_node->coef=head1->coef;        /*設(shè)置系數(shù)*/
               new_node->exp=head1->exp;          /*設(shè)置指數(shù)*/
               head1=head1->next;                 /*指向下一結(jié)點(diǎn)*/
               }
               else                   /*多項(xiàng)式的指數(shù)相等*/
                {
            /*系數(shù)相加*/
                new_node->coef=head1->coef+head2->coef;
                new_node->exp=head1->exp;       /*設(shè)置指數(shù)*/
                head1=head1->next;             /* 指向下一結(jié)點(diǎn)*/
                head2=head2->next;             /* 指向下一結(jié)點(diǎn)*/
                }
            before->next=new_node;              /*將前一結(jié)點(diǎn)指向新結(jié)點(diǎn)*/
            before=new_node;                    /*新結(jié)點(diǎn)成為前結(jié)點(diǎn)*/
            }
            new_node->next=result;               /*創(chuàng)建環(huán)狀鏈接*/
            return result;                       /*返回多項(xiàng)式的指針*/
            }
            void main()
            {
            plink poly1;       /*多項(xiàng)式1的指針*/
            plink poly2;       /*多項(xiàng)式2的指針*/
            plink result;      /*多項(xiàng)式結(jié)果的指針*/
            int list1[6]={4,0,3,0,7,0};   /*數(shù)組1的內(nèi)容*/
            int list2[6]={9,7,1,0,5,6};   /*數(shù)組2的內(nèi)容*/
            poly1=createpoly(list1,6);    /*創(chuàng)建多項(xiàng)式1*/
            printf("the content1:");
            printpoly(poly1);           /*輸出多項(xiàng)式1*/
            poly2=createpoly(list2,6);     /*創(chuàng)建多項(xiàng)式2*/
            printf("the content2:");
            printpoly(poly2);           /*輸出多項(xiàng)式2*/
            result=polyadd(poly1,poly2);      /*多項(xiàng)式相加*/
            printf("the add:");
            printpoly(result);         /*輸出多項(xiàng)式結(jié)果*/
            }

            posted @ 2012-02-28 00:34 hoshelly 閱讀(298) | 評(píng)論 (0)編輯 收藏

            #include<stdio.h>
            #include<stdlib.h>
            //雙向鏈表結(jié)構(gòu)
            struct dlist
            {
                int data;
            struct dlist *front;//指向下一結(jié)點(diǎn)的指針
            struct dlist *back;//指向前一結(jié)點(diǎn)的指針
            };
            typedef struct dlist dnode;
            typedef dnode *dlink;
            dlink createdlist(int *array,int len)
            {
               dlink head;
               dlink before;
               dlink new_node;
               int i;
               //創(chuàng)建第一個(gè)結(jié)點(diǎn),分配指針內(nèi)存
               head=(dlink)malloc(sizeof(dnode));
               if(!head)
               return NULL;
               head->data=array[0];
               head->front=NULL;
               head->back=NULL;
               before=head;//指向第一個(gè)結(jié)點(diǎn)
               
               for(i=1;i<len;i++)//用循環(huán)創(chuàng)建其他結(jié)點(diǎn)
               {
                  new_node=(dlink)malloc(sizeof(dnode));
              if(!new_node)
              return NULL;
              new_node->data=array[i];
              new_node->front=NULL;
              new_node->back=before;//將新結(jié)點(diǎn)指向前結(jié)點(diǎn)
              before->front=new_node;//將前結(jié)點(diǎn)指向新結(jié)點(diǎn),構(gòu)成循環(huán)鏈表
              before=new_node;//新結(jié)點(diǎn)成為前結(jié)點(diǎn)
            }
            return head;
            }
            //雙向鏈表的輸出
            void printdlist(dlink head,dlink now)
            {
               while(head!=NULL) //鏈表循環(huán)遍歷
               {
                  if(head == now)
              printf("#%d#",head->data);
              else
                 printf("[%d]",head->data);
              head=head->front;
            }
            printf("\n");
            }
            void main()
            {
               dlink head;
               dlink now=NULL;
               int list[6]={1,2,3,4,5,6};
               int select;
               
               head=createdlist(list,6);
               if(head==NULL)
               {
                  printf("內(nèi)存分配失敗!\n");
              exit(1);
                }
            now=head;
            while(1)
            {
               printf("鏈表內(nèi)容是:");
               printdlist(head,now);
               printf("[1]往下移動(dòng) [2]往回移動(dòng) [3]離開(kāi) ==> ");
               scanf("%d",&select);
               switch(select)
               {
                  case 1: if(now->front!=NULL)
                       now=now->front;
               break;
              case 2: if(now->back!=NULL)
                       now=now->back;
               break;
              case 3:  exit(1);
                }
            }
            }

            posted @ 2012-02-28 00:34 hoshelly 閱讀(170) | 評(píng)論 (0)編輯 收藏


            描述

            輝輝、姍姍和佳佳是好朋友,他們一起參加了在湖南長(zhǎng)沙長(zhǎng)郡中學(xué)舉辦的第二十一屆全國(guó)青少年信息學(xué)奧林匹克競(jìng)賽(NOI2004)。他們很早就來(lái)到了長(zhǎng)沙,可是報(bào)名還沒(méi)有開(kāi)始。怎么辦呢?他們決定分頭出去玩一天,晚上回到宿舍以后給大家說(shuō)說(shuō)自己這一天做了什么有意義的事情。
            你一定想不到輝輝干嘛去了——他睡了一天。他想:“比賽前幾天老是寫(xiě)程序到深夜,頭暈暈的……沒(méi)關(guān)系,好好睡一覺(jué),然后我會(huì)精神抖擻。醒了之后,我要做有意義的事情。”這一睡可不得了,輝輝從早上a點(diǎn)b分c秒一直睡到了下午d點(diǎn)e分f秒。他睡了多少秒鐘呢?

            輸入

            測(cè)試數(shù)據(jù)包含多組輸入。 每組輸入一行,僅包含六個(gè)非負(fù)整數(shù)a, b, c, d, e, f,以空格分離。1<=a, d<=11, 0<=b, c, e, f<=59。如輸入6 5 4 3 2 1表示輝輝從06:05:04睡到15:02:01。 輸入以六個(gè)零結(jié)尾。

            輸出

            每組輸出一行,僅包含一個(gè)整數(shù)s,即輝輝睡覺(jué)的總秒數(shù)。

            樣例輸入
            6 5 4 3 2 1 0 0 0 0 0 0
            樣例輸出
            32217 

            注意秒、分、時(shí)之間當(dāng)不同大小時(shí)要進(jìn)行適當(dāng)?shù)慕?運(yùn)算
            源代碼如下(感覺(jué)挺丑陋的):

            #include
            <iostream>
            using namespace std;
            int main()
            {
                
            int a,b,c,d,e,f;
                
            int h,m,s,sum;
                
            while(cin>>a>>b>>c>>d>>e>>f)
                {
                    
            if(a==0&&b==0&&c==0&&d==0&&e==0&&f==0)
                        
            break;

                          
            if(b>e)//醒來(lái)的時(shí)刻的分鐘數(shù)大于睡時(shí)的分鐘數(shù)
                           {
                            h
            =d-a+11;//小時(shí)減1
                            
            if(c>f)
                            {
                                s
            =f-c+60;
                                m
            =e-b+59;
                            }
                            
            else
                            {
                                s
            =f-c;
                                m
            =e-b+60;
                            }
                           }
                         
            else if(b<e)
                         {
                            h
            =d-a+12;
                            
            if(c>f)
                            {
                                s
            =f-c+60;
                                m
            =e-b-1;
                            }
                            
            else
                            {
                                s
            =f-c;
                                m
            =e-b;
                            }
                          }
                        
            else if(b==e)
                        {
                            
            if(c>f)
                            {
                                h
            =d-a+11;
                                m
            =e-b+59;
                                s
            =f-c+60;
                            }
                            
            else
                            {
                                h
            =d-a+12;
                                m
            =e-b;
                                s
            =f-c;
                            }
                         }

                         sum
            =h*3600+m*60+s;//全部換算成統(tǒng)一單位——秒
                         cout
            <<sum<<endl;
                }
                
            return 0;
            }

            posted @ 2012-02-26 20:14 hoshelly 閱讀(178) | 評(píng)論 (0)編輯 收藏

            為防止在對(duì)數(shù)組動(dòng)態(tài)賦值時(shí)發(fā)生數(shù)組越界,C++提供了一種能夠解決此問(wèn)題的方法——重載運(yùn)算符[]。示例程序:
            #include<iostream>
            class CArray
            {
               
            public:
               CArray(
            int l)
               {
                   length
            =l;
                   Buff
            =new char[length];
               }
               
            ~CArray(){delete Buff;}
               
            int GetLength(){return length;}
               
            char& operator [](int i);
               
            private:
               
            int length;
               
            char *Buff;
            };

            char & CArray::operator[](int i)
            {
                
            static char ch=0;
                
            if(i<length && i>=0)
                    
            return Buff[i];
                
            else
                {
                    cout
            <<"\nIndex out of range.";
                    
            return ch;
                }
            }

            void main()
            {
                
            int cnt;
                CArray string1(
            6);
                
            char *string2="string";
                
            for(cnt=0;cnt<string1.GetLength();cnt++)
                    string1[cnt]
            =string2[cnt];
                    cout
            <<"\n";
                    
            for(cnt=0;cnt<string1.GetLength();cnt++)
                       cout
            <<string1[cnt];
                    cout
            <<"\n";
                cout
            <<string1.GetLength()<<endl;
            }
            在重載下標(biāo)運(yùn)算符函數(shù)時(shí)注意:
            1)該函數(shù)只帶一個(gè)參數(shù),不可帶多個(gè)參數(shù)。
            2)得重載為友元函數(shù),必須是非static類(lèi)的成員函數(shù)。

            posted @ 2012-02-24 00:08 hoshelly 閱讀(1667) | 評(píng)論 (0)編輯 收藏

            僅列出標(biāo)題
            共12頁(yè): First 4 5 6 7 8 9 10 11 12 
            国产精品99久久久精品无码| 久久精品麻豆日日躁夜夜躁| 狠狠精品干练久久久无码中文字幕| 嫩草影院久久国产精品| 四虎影视久久久免费观看| 久久亚洲私人国产精品vA| 久久se精品一区二区影院 | 久久亚洲欧美国产精品| 精品熟女少妇aⅴ免费久久| 97久久婷婷五月综合色d啪蜜芽| 热久久这里只有精品| 国内高清久久久久久| 精品国产青草久久久久福利| 久久综合精品国产二区无码| 9999国产精品欧美久久久久久 | 久久成人精品视频| 97精品依人久久久大香线蕉97 | 国产成人精品久久综合| 久久天天躁狠狠躁夜夜96流白浆| 青青热久久国产久精品| 国产精品女同一区二区久久| 色综合久久无码五十路人妻| 亚洲国产日韩欧美综合久久| 久久精品国产亚洲精品| 狠狠色丁香婷婷久久综合不卡| 亚洲狠狠婷婷综合久久久久| 亚洲综合久久夜AV | 一本大道久久东京热无码AV | 久久精品成人| 久久人人爽人人澡人人高潮AV | 久久精品国产国产精品四凭| 伊人久久综在合线亚洲2019| 久久伊人精品青青草原高清| 日本福利片国产午夜久久| 99久久免费国产精品热| 亚洲狠狠综合久久| 国产精品丝袜久久久久久不卡| 青青草国产精品久久久久| 国产成人无码精品久久久免费| 精品99久久aaa一级毛片| 久久精品三级视频|