Archive for the ‘103(暑)資料結構’ Category

13
七月

暑期營程式設計 07/13: opd-reserve.php

   Posted by: admin Tags: ,

<?php
$pdo = new PDO('mysql:host=localhost;dbname=hospital;charset=utf8', 'admin01', 'admin01');
$pdo->query("set names utf8");
 
$title="一般內科";
$doctors = array (
    "w1"  => array("morning" => "", "afternoon" => "", "night" => ""),
    "w2"  => array("morning" => "", "afternoon" => "", "night" => ""),
	"w3"  => array("morning" => "", "afternoon" => "", "night" => ""),
    "w4"  => array("morning" => "", "afternoon" => "", "night" => ""),
	"w5"  => array("morning" => "", "afternoon" => "", "night" => ""),
    "w6"  => array("morning" => "", "afternoon" => "", "night" => ""),
	"w7"  => array("morning" => "", "afternoon" => "", "night" => "")
);
$depID = "31800";
if (isset($_GET["depID"]))
	$depID = $_GET["depID"];
 
$sql = "SELECT departName FROM `opd` WHERE departID='".$depID."'";
$pdoStatement = $pdo->prepare($sql);
$ret = $pdoStatement->execute();
$row = $pdoStatement->fetch();
$title=$row["departName"];
 
$sql = "SELECT id, dname, vsection, vday FROM schedule WHERE depID='".$depID."'";
$pdoStatement = $pdo->prepare($sql);
$ret = $pdoStatement->execute();
$rowsSchedule = $pdoStatement->fetchAll();
$array_dname = array();//醫生的名字
foreach ($rowsSchedule as $rowS)
{
  $array_dname[$rowS["id"]] = $rowS["dname"];
}
 
$sql = "SELECT id, scheduleID, depID, count, max, visit_date, comment FROM reservation WHERE depID ='".$depID."'";
$pdoStatement = $pdo->prepare($sql);
$ret = $pdoStatement->execute();
$rowsReservation = $pdoStatement->fetchAll();
$array_count = array();
$array_max = array();
$array_reserveID = array();
foreach ($rowsReservation as $rowR)
{
  $array_count[$rowR["scheduleID"]][$rowR["visit_date"]] = $rowR["count"];
  $array_max[$rowR["scheduleID"]][$rowR["visit_date"]] = $rowR["max"];
  $array_reserveID[$rowR["scheduleID"]][$rowR["visit_date"]] = $rowR["id"];
}
//時間處理
$w = array();
$dtVisit = new DateTime();
$dtBegin = new DateTime();
$dtVisit->modify('monday this week');
for ($i = 1; $i <= 7; $i++) 
{
   $enable = true;
   if ($dtVisit < $dtBegin) 
      $enable = false;
 
   $theday = $dtVisit->format('Y-m-d');
   $w[$i]=$theday ;
   foreach ($rowsSchedule as $rowD)
   {
      $sid = $rowD["id"];
      if ($i==1 && $rowD["vday"] == "星期一")
      {
         if ($rowD["vsection"] == "上午")
            $doctors["w1"]["morning"] .=markup($enable, $sid, $theday, $array_dname, $array_count, $array_max, $array_reserveID);
         else if ($rowD["vsection"] == "下午")
            $doctors["w1"]["afternoon"] .=markup($enable, $sid, $theday, $array_dname, $array_count, $array_max, $array_reserveID);
         else if ($rowD["vsection"] == "晚上")
            $doctors["w1"]["night"] .=markup($enable, $sid, $theday, $array_dname, $array_count, $array_max, $array_reserveID);
      }
      else if ($i==2 && $rowD["vday"] == "星期二")
      {
         if ($rowD["vsection"] == "上午")
            $doctors["w2"]["morning"] .=markup($enable, $sid, $theday, $array_dname, $array_count, $array_max, $array_reserveID);
         else if ($rowD["vsection"] == "下午")
            $doctors["w2"]["afternoon"] .=markup($enable, $sid, $theday, $array_dname, $array_count, $array_max, $array_reserveID);
         else if ($rowD["vsection"] == "晚上")
            $doctors["w2"]["night"] .=markup($enable, $sid, $theday, $array_dname, $array_count, $array_max, $array_reserveID);
      }
      else if ($i==3 && $rowD["vday"] == "星期三")
      {
         if ($rowD["vsection"] == "上午")
            $doctors["w3"]["morning"] .=markup($enable, $sid, $theday, $array_dname, $array_count, $array_max, $array_reserveID);
         else if ($rowD["vsection"] == "下午")
            $doctors["w3"]["afternoon"] .=markup($enable, $sid, $theday, $array_dname, $array_count, $array_max, $array_reserveID);
         else if ($rowD["vsection"] == "晚上")
            $doctors["w3"]["night"] .=markup($enable, $sid, $theday, $array_dname, $array_count, $array_max, $array_reserveID);
      }
      else if ($i==4 && $rowD["vday"] == "星期四")
      {
         if ($rowD["vsection"] == "上午")
            $doctors["w4"]["morning"] .=markup($enable, $sid, $theday, $array_dname, $array_count, $array_max, $array_reserveID);
         else if ($rowD["vsection"] == "下午")
            $doctors["w4"]["afternoon"] .=markup($enable, $sid, $theday, $array_dname, $array_count, $array_max, $array_reserveID);
         else if ($rowD["vsection"] == "晚上")
            $doctors["w4"]["night"] .=markup($enable, $sid, $theday, $array_dname, $array_count, $array_max, $array_reserveID);
      }
      else if ($i==5 && $rowD["vday"] == "星期五")
      {
         if ($rowD["vsection"] == "上午")
            $doctors["w5"]["morning"] .=markup($enable, $sid, $theday, $array_dname, $array_count, $array_max, $array_reserveID);
         else if ($rowD["vsection"] == "下午")
            $doctors["w5"]["afternoon"] .=markup($enable, $sid, $theday, $array_dname, $array_count, $array_max, $array_reserveID);
         else if ($rowD["vsection"] == "晚上")
            $doctors["w5"]["night"] .=markup($enable, $sid, $theday, $array_dname, $array_count, $array_max, $array_reserveID);
      }
      else if ($i==6 && $rowD["vday"] == "星期六")
      {
         if ($rowD["vsection"] == "上午")
            $doctors["w6"]["morning"] .=markup($enable, $sid, $theday, $array_dname, $array_count, $array_max, $array_reserveID);
         else if ($rowD["vsection"] == "下午")
            $doctors["w6"]["afternoon"] .=markup($enable, $sid, $theday, $array_dname, $array_count, $array_max, $array_reserveID);
         else if ($rowD["vsection"] == "晚上")
            $doctors["w6"]["night"] .=markup($enable, $sid, $theday, $array_dname, $array_count, $array_max, $array_reserveID);
      }
      else if ($i==7 && $rowD["vday"] == "星期日")
      {
         if ($rowD["vsection"] == "上午")
            $doctors["w7"]["morning"] .=markup($enable, $sid, $theday, $array_dname, $array_count, $array_max, $array_reserveID);
         else if ($rowD["vsection"] == "下午")
            $doctors["w7"]["afternoon"] .=markup($enable, $sid, $theday, $array_dname, $array_count, $array_max, $array_reserveID);
         else if ($rowD["vsection"] == "晚上")
            $doctors["w7"]["night"] .=markup($enable, $sid, $theday, $array_dname, $array_count, $array_max, $array_reserveID);
      }
   }
 
   $dtVisit->modify('+1 day');
}
function markup($enable, $sid, $date, $array_dname, $array_count, $array_max, $array_reserveID)
{
   $dname= $array_dname["$sid"];
   if ($enable)
   {
      $count = $array_count["$sid"]["$date"];
      $max = $array_max["$sid"]["$date"];
      $rid = $array_reserveID["$sid"]["$date"];
      $a='<a href="opd-reserve-form.php?sid='.$sid.'&rid='.$rid.'">'.$dname.'</a>(預約:'.$count.'/'.$max.')<br>';
   }
   else
      $a=$dname.'()<br>';
   return $a;
}
 
?>
<!-- saved from url=(0089)http://www.cmuh.cmu.edu.tw/html/portlet/cmuh/schedule/DymSchedule.jsp?catId=1&depId=31800 -->
<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<link rel="stylesheet" type="text/css" href="./DymSchedule_files/schedule.css">
</head>
 
 
<body><div id="schtab">
 
	<table class="sch">
			<!-- 抓Tittle -->
			<caption><?php echo $title ?></caption>
 
		<tbody><tr>	<td class="firstth"></td>
<th class="outertop"><center>星期一(<?php echo $w[1] ?>)</center></th><th class="outertop"><center>星期二(<?php echo $w[2] ?>)</center></th><th class="outertop"><center>星期三(<?php echo $w[3] ?>)</center></th><th class="outertop"><center>星期四(<?php echo $w[4] ?>)</center></th><th class="outertop"><center>星期五(<?php echo $w[5] ?>)</center></th><th class="outertop"><center>星期六(<?php echo $w[6] ?>)</center></th><th class="outertop"><center>星期日(<?php echo $w[7] ?>)</center></th>
 
		</tr>
 
 
			<tr>	
<th class="outerleft"><center>上午 <br>08:30<br><div class="outerleft_pic"></div><br>12:00</center></th>
						<td class="inner1">
 
								<?php echo $doctors["w1"]["morning"] ?>
 
						</td>
 
 
						<td class="inner2">
 
								<?php echo $doctors["w2"]["morning"] ?>
 
						</td>
 
 
						<td class="inner1">
								<?php echo $doctors["w3"]["morning"] ?>
						</td>
 
 
						<td class="inner2">
 
								<?php echo $doctors["w4"]["morning"] ?>
						</td>
 
 
						<td class="inner1">
 
								<?php echo $doctors["w5"]["morning"] ?>
 
						</td>
 
 
						<td class="inner2">
								<?php echo $doctors["w6"]["morning"] ?>
						</td>
 
 
						<td class="inner1">
								<?php echo $doctors["w7"]["morning"] ?>
						</td>
			</tr>
 
 
			<tr>	
<th class="outerleft"><center>下午<br>13:30<br><div class="outerleft_pic"></div><br>17:00</center></th>
						<td class="inner1">
 
								<?php echo $doctors["w1"]["afternoon"] ?>
 
						</td>
 
 
						<td class="inner2">
 
								<?php echo $doctors["w2"]["afternoon"] ?>
 
						</td>
 
 
						<td class="inner1">
								<?php echo $doctors["w3"]["afternoon"] ?>
						</td>
 
 
						<td class="inner2">
 
								<?php echo $doctors["w4"]["afternoon"] ?>
						</td>
 
 
						<td class="inner1">
 
								<?php echo $doctors["w5"]["afternoon"] ?>
 
						</td>
 
 
						<td class="inner2">
								<?php echo $doctors["w6"]["afternoon"] ?>
						</td>
 
 
						<td class="inner1">
								<?php echo $doctors["w7"]["afternoon"] ?>
						</td>
 
 
			</tr>
 
 
			<tr>	
<th class="outerleft"><center>晚上<br>18:30<br><div class="outerleft_pic"></div><br>21:00</center></th>
						<td class="inner1">
 
								<?php echo $doctors["w1"]["night"] ?>
 
						</td>
 
 
						<td class="inner2">
 
								<?php echo $doctors["w2"]["night"] ?>
 
						</td>
 
 
						<td class="inner1">
								<?php echo $doctors["w3"]["night"] ?>
						</td>
 
 
						<td class="inner2">
 
								<?php echo $doctors["w4"]["night"] ?>
						</td>
 
 
						<td class="inner1">
 
								<?php echo $doctors["w5"]["night"] ?>
 
						</td>
 
 
						<td class="inner2">
								<?php echo $doctors["w6"]["night"] ?>
						</td>
 
 
						<td class="inner1">
								<?php echo $doctors["w7"]["night"] ?>
						</td>
 
 
			</tr>
 
 
</tbody></table>
 
			<p class="schedule_p">
 
			</p>
			<div class="clear"></div>
 
</div></body></html>

bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark

3
九月

資料結構程式 09/03: ex11.c

   Posted by: admin Tags: , ,

#include <stdio.h> //標準輸出入函數的標頭檔
#include <stdlib.h>
typedef struct node//節點結構的自定型別定義 
{
    int data;//整數 
    struct node *left;//節點的指標 
    struct node *right;//節點的指標
} Node;
Node* NewNode()
{
    Node *newNode = malloc(sizeof(Node));//新節點(node) 
    newNode->data = 0;
    newNode->left = NULL;
    newNode->right = NULL;
    return  newNode; 
}
void Travel(Node* curNode)
{
     if (curNode==NULL)
        return;
     Travel(curNode->left);//走訪左子樹
     printf("%3d ", curNode->data);//走訪樹根
     Travel(curNode->right);//走訪右子樹
}
int main(int argc, char *argv[])//
{//程式寫在main()函數裡
    Node* Tree = NewNode();
    Node* curNode = NULL;
    int i, newdata;
    srand( (unsigned) time( NULL ) );//srand()是產生亂數的種子
    //插入20個資料項到這個樹
    newdata = rand()%100;
    Tree->data = newdata;
    for (i=1; i< 20; i++)
    {
        newdata = rand()%100;
        curNode = Tree       
        while (1)
        {
              if (newdata < curNode->data)
              {
                 if (curNode->left == NULL)
                 {
                     curNode->left = NewNode();
                     curNode->left->data = newdata;
                     break;                                
                 }
                 else
                     curNode = curNode->left;
              }
              else
              {
                 if (curNode->right == NULL)
                 {
                     curNode->right = NewNode();
                     curNode->right->data = newdata;
                     break;                                   
                 }
                 else
                     curNode = curNode->right;
              }
        }        
    }
    //使用中序列印出整個二元搜尋樹
    Travel(Tree);
    return 0;

bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark

1
九月

資料結構程式 09/01: ex10.c

   Posted by: admin Tags: , ,

#include <stdio.h> //標準輸出入函數的標頭檔
#include <stdlib.h>
void Travel(int* Tree, int curNode)
{
     if (Tree[curNode]==-1)
        return;
     Travel(Tree, curNode * 2);//走訪左子樹
     printf("%3d ", Tree[curNode]);//走訪樹根
     Travel(Tree, curNode * 2 + 1);//走訪右子樹
}
int main(int argc, char *argv[])//主函數入口
 
    int Level = 12;
    int Nodes = 8192;
    int Tree[Nodes];
    int i, j, data, curNode, curLevel;
    srand( (unsigned) time( NULL ) );//srand()是產生亂數的種子
    //讓每個節點啟始值是-1表示是空的 
    for (i=0; i< Nodes; i++)
        Tree[i] = -1;
    //插入20個資料項到這個樹
    for (i=0; i< 20; i++)
    {
        data = rand()%100;
        curNode = 1;//根節點是編號是1 
        curLevel = 1;//目前階層 
        while (curLevel <= Level)
        { 
          if (Tree[curNode] == -1)//目前節點是空的
          { 
            Tree[curNode] = data;
            break;
          } 
          else if (data < Tree[curNode])
            curNode = 2 * curNode;
          else //if (data >= Tree[curNode])
              curNode = 2 * curNode +1;
          curLevel++; 
        } 
    }
    //使用中序列印出整個二元搜尋樹
    Travel(Tree, 1);
    return 0; 
}

bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark

29
八月

資料結構程式 08/29: ex9.c

   Posted by: admin Tags: , ,

Node* push(Node *stack, int indata)
{
     Node *newNode = malloc(sizeof(Node))//新節點(node) 
     newNode->data = indata;
     newNode->next = stack;
     return newNode;
}
Node* pop(Node *stack)
{
    Node *oldnode = stack;
    stack = stack->next;
    free(oldnode);
    return stack;
}
int main()
{
    Node *stack = NULL;
    int i;
    srand( (unsigned) time( NULL ) )//srand()是產生亂數的種子
    //在這個堆疊上push資料 
    for (i=1; i<5; i++)
 
        stack = push(stack, rand()%100);
        PrintList(stack);
    }
    //在這個堆疊上pop資料 
    for (i=1; i<5; i++)
 
        stack = pop(stack);
        PrintList(stack);
    }
}

bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark

27
八月

資料結構程式 08/27: ex8.c

   Posted by: admin Tags: , ,

void FreeList(Node *listA)
{
    Node *curNode = listA;
    Node *nextNode;
    while ( curNode !=NULL)//從第一個節點把節點釋放 
    {
        nextNode = curNode->next;
        free(curNode);
        curNode = nextNode;
    }   
}
main()
{
   Node *prevNode;//->操作刪除時要記住前一個的指標
    Node *delNode;//->操作刪除的節點
 
  //在這個串列刪除節點
    if (listA!=NULL && listA->data >=30 && listA->data <=60)
       listA = listA->next;
    if (listA!=NULL)
    {
        prevNode = listA; curNode = listA->next;
        while (curNode!=NULL)
        {
              delNode = NULL; 
              if (curNode->data >=30 && curNode->data <=60)
              {
                  prevNode->next = curNode->next;
                  delNode = curNode; 
              }
              else
              {
                  prevNode = curNode;
              }
              curNode = curNode->next;
              if (delNode!=NULL)
                 free(delNode);
        }
    }
    PrintList(listA);
    FreeList(listA); // 釋放節點
}

bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark