當前位置:首頁 » 操作系統 » h2源碼

h2源碼

發布時間: 2022-08-24 08:59:47

㈠ 學生管理系統php源碼誰有

php學生管理系統源碼,供大家參考,具體內容如下

功能:

1.添加/刪除/修改
2.數據存儲.
界面分布:
index.php
--->主界面
add.php --->stu添加
action ---> sql中add/del/update
(處理html表單-->mysql的數據存儲 && 頁面跳轉)
edit.php --->stu修改
menu.php
-->首頁

1. index.php
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>學生信息管理</title>
<script>
function doDel(id) {
if(confirm('確認刪除?')) {
window.location='action.php?action=del&id='+id;
}
}
</script>
</head>
<body>
<center>
<?php
include ("menu.php");
?>
<h3>瀏覽學生信息</h3>
<table width="500" border="1">
<tr>
<th>ID</th>
<th>姓名</th>
<th>性別</th>
<th>年齡</th>
<th>班級</th>
<th>操作</th>
</tr>
<?php
// 1. 鏈接資料庫
try{
$pdo = new PDO("uri:mysqlPdo.ini","root","1");
}catch (PDOException $e) {
die('connection failed'.$e->getMessage());
}
//2.執行sql
$sql_select = "select * from stu";
//3.data 解析
foreach ( $pdo->query($sql_select) as $row) {
echo "<tr>";
echo "<th>{$row['id']} </th>";
echo "<th>{$row['name']}</th>";
echo "<th>{$row['sex']} </th>";
echo "<th>{$row['age']} </th>";
echo "<th>{$row['classid']}</th>";
echo "<td>
<a href='edit.php?id={$row['id']}'>修改</a>
<a href='javascript:void(0);' onclick='doDel({$row['id']})'>刪除</a>
</td>";
echo "</tr>";
}
?>
</table>
</center>
</body>
</html>

2. add.php
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>學生管理系統</title>
</head>
<body>
<center>

<?php include ('menu.php'); ?>
<h3>增加學生信息</h3>
<form action="action.php?action=add" method="post">
<table>
<tr>
<td>姓名</td>
<td><input type="text" name="name"></td>
</tr>
<tr>
<td>年齡</td>
<td><input type="text" name="age"></td>
</tr>
<tr>
<td>性別</td>
<td><input type="radio" name="sex" value="男">男</td>
<td><input type="radio" name="sex" value="女">女</td>
</tr>
<tr>
<td>班級</td>
<td><input type="text" name="classid"></td>
</tr>
<tr>
<!-- <td> </td>-->
<td><a href="index.php">返回</td>
<td><input type="submit" value="添加"></td>
<td><input type="reset" value="重置"></td>
</tr>
</table>
</form>

</center>
</body>
</html>

3. action.php
<?php
/**
* Created by PhpStorm.
* User: hyh
* Date: 16-7-7
* Time: 下午9:37
*/
//1. 鏈接資料庫
try{
$pdo = new PDO("uri:mysqlPdo.ini","root","1");
}catch (PDOException $e) {
// echo 'Connection failed: ' . $e->getMessage();
die('connection failed'.$e->getMessage());
}

//2.action 的值做對操作

switch ($_GET['action']){

case 'add'://add
$name = $_POST['name'];
$sex = $_POST['sex'];
$age = $_POST['age'];
$classid = $_POST['classid'];

$sql = "insert into stu (name, sex, age, classid) values ('{$name}', '{$sex}','{$age}','{$classid}')";
$rw = $pdo->exec($sql);
if ($rw > 0){
echo "<script>alter('添加成功');</script>";
}else{
echo "<script>alter('添加失敗');</script>";
}
header('Location: index.php');
break;

case 'del'://get
$id = $_GET['id'];
$sql = "delete from stu where id={$id}";
$rw = $pdo->exec($sql);
if ($rw > 0){
echo "<script>alter('刪除成功');</script>";
}else{
echo "<script>alter('刪除失敗');</script>";
}
header('Location: index.php');
break;

case 'edit'://post
$id = $_POST['id'];
$name = $_POST['name'];
$age = $_POST['age'];
$classid = $_POST['classid'];
$sex = $_POST['sex'];

// echo $id, $age, $age, $name;
$sql = "update stu set name='{$name}', age={$age},sex='{$sex}',classid={$classid} where id={$id};";
// $sql = "update myapp.stu set name='jike',sex='女', age=24,classid=44 where id=17";
print $sql;
$rw = $pdo->exec($sql);
if ($rw > 0){
echo "<script>alter('更新成功');</script>";
}else{
echo "<script>alter('更新失敗');</script>";
}
header('Location: index.php');
break;

default:
header('Location: index.php');
break;
}

4.edit.php
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>學生管理系統</title>
</head>
<body>
<center>
<?php include ('menu.php');
//1. 鏈接資料庫
try{
$pdo = new PDO("uri:mysqlPdo.ini","root","1");
}catch (PDOException $e) {
die('connection failed'.$e->getMessage());
}
//2.執行sql
$sql_select = "select * from stu where id={$_GET['id']}";
$stmt = $pdo->query($sql_select);
if ($stmt->rowCount() >0) {
$stu = $stmt->fetch(PDO::FETCH_ASSOC); // 解析數據
}else{
die("no have this id:{$_GET['id']}");
}
?>

<h3>修改學生信息</h3>

<form action="action.php?action=edit" method="post">
<input type="hidden" name="id" value="<?php echo $stu['id'];?>">
<table>
<tr>
<td>姓名</td>
<td><input type="text" name="name" value="<?php echo $stu['name'];?>"></td>
</tr>
<tr>
<td>年齡</td>
<td><input type="text" name="age" value="<?php echo $stu['age'];?>"></td>
</tr>
<tr>
<td>性別</td>
<td>
<input type="radio" name="sex" value="男" <?php echo ($stu['sex'] == "男")? "checked":"";?> >男
</td>
<td>
<input type="radio" name="sex" value="女" <?php echo ($stu['sex'] == "女")? "checked":"";?> >女
</td>
</tr>
<tr>
<td>班級</td>
<td><input type="text" name="classid" value="<?php echo $stu['classid']?>"></td>
</tr>
<tr>
<td> </td>
<td><input type="submit" value="更新"></td>
<td><input type="reset" value="重置"></td>
</tr>
</table>
</form>

</center>

<?php
?>
</body>
</html>

5. menu.php

<!DOCTYPE html>
<html lang="en">
<body>
<h2>學生管理系統</h2>
<a href="index.php"> 瀏覽學生</a>
<a href="add.php"> 添加學生</a>
<hr>
</body>
</html>

㈡ 這個鏈接下的源代碼是什麼

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>合租女孩洗澡不關門,用手機拍了幾張相片。。【好圖共賞】 |女人心情_ 搖籃論壇 </title>
<meta name="keywords" content="" />
<meta name="description" content=" 搖籃論壇 " />
<link rel="archives" title="搖籃論壇" href="http://bbs.yaolan.com/archiver/" />

<link href="http://loginbar.yaolan.com/css/dh.css" rel="stylesheet" type="text/css" />
<style type="text/css">
.dh_nav_r_m .menu input{ margin-top:6px;padding:0;}
</style>
<link rel="stylesheet" type="text/css" href="forumdata/cache/style_7_viewthread.css" />
<link rel="stylesheet" type="text/css" href="forumdata/cache/style_7_common.css" />
<script type="text/javascript">
var discuz_uid = 0;var IMGDIR = 'images/default';var attackevasive = '0';var gid = 0;var STYLEID = '7';
gid = parseInt('204');var fid = parseInt('24');var tid = parseInt('51269126');
</script>
<script src="include/javascript/common.js" type="text/javascript"></script>
<script src="http://bbs.yaolan.com/Js/jAppear.js?v=20081030" type="text/javascript"></script>
<link href="http://bbs.yaolan.com/css/Popo.css?v=20081030" rel="stylesheet" type="text/css" />
</head>

<body onkeydown="if(event.keyCode==27) return false;" onload="ShopAuth(3,'onload');">

<div id="menuinfo" >
<div id="nav_nav">

<script src="http://loginbar.yaolan.com/GetUserInfo.aspx" type="text/javascript"></script>
<script src="http://my.yaolan.com/Message/GetNewInfosCount1.aspx" type="text/javascript"></script>
<script src="http://loginbar.yaolan.com/js/loginbar.js" type="text/javascript"></script>

<ul style="width:450px">
<li class="menu1 wc_nav_bg1"><a href="http://www.yaolan.com/" target="_blank" class="wc_nav_nav">搖籃首頁</a></li>
<li class="menu1 wc_nav_bg1"><a href="http://abc.yaolan.com/" target="_blank" class="wc_nav_nav">成長階梯</a></li>
<li class="menu1 wc_nav_bg1"><a href="http://www.yaolan.com/index/" target="_blank" class="wc_nav_nav">育兒知識</a></li>
<li class="menu2 wc_nav_bg2" onmouseover="this.className='menu1 wc_nav_bg2'" onmouseout="this.className='menu2 wc_nav_bg2'">
<a href="http://ask.yaolan.com/" target="_blank" class="wc_nav_nav">育兒問答</a>
<div class="list">
<a href="http://www.1.yaolan.com/shequ/chat/index.asp" target="_blank">專家在線</a><br />
</div>
</li>
<li class="menu2 wc_nav_bg2" onmouseover="this.className='menu1 wc_nav_bg2'" onmouseout="this.className='menu2 wc_nav_bg2'">
<a href="http://baobao.yaolan.com/" target="_blank" class="wc_nav_nav">寶貝主頁</a>
<div class="list">
<a href="http://baobao.yaolan.com/jsp/bloglist/list.jsp" target="_blank">寶寶日記</a><br />
<a href="http://cn.yaolan.com/cn/" target="_blank">寶寶域名</a><br />
<a href="http://diy.yaolan.com/" target="_blank">個性定製</a><br />
<a href="http://bless.yaolan.com/getKnot.aspx" target="_blank">送祝福</a><br />
</div>
</li>
<li class="menu1 wc_nav_bg1"><a href="http://bbs.yaolan.com/" target="_blank" class="wc_nav_nav">
育兒論壇</a></li>
<li class="menu2 wc_nav_bg2" onmouseover="this.className='menu1 wc_nav_bg2'" onmouseout="this.className='menu2 wc_nav_bg2'">
<a href="http://emag.yaolan.com/" target="_blank" class="wc_nav_nav">電子雜志</a>
<div class="list">
<a href="http://emag.yaolan.com/ezine/mama.shtml" target="_blank">准媽媽系列</a><br />
<a href="http://emag.yaolan.com/ezine/0-1.shtml" target="_blank">0-1系列</a><br />
<a href="http://emag.yaolan.com/ezine/1-3.shtml" target="_blank">1-3系列</a><br />
</div>
</li>
</ul>
</div>

</div>
<div id="append_parent"></div><div id="ajaxwaitid"></div>
<div class="wrap">
<div id="header">
<h2><div style="margin-top:15px"><a href="index.html" title="搖籃論壇"><img src="images/default/bbslogo.jpg" alt="搖籃論壇" border="0" /></a></div></h2>
<div id="ad_headerbanner"><iframe id="banner2" width="630" height="65" scrolling="no" frameborder="0" marginheight="0" marginwidth="0" class="left" src="http://adnet.yaolan.com/GetCommonAds.aspx?pos_id=321" ></iframe></div>
</div>

<div style="width:100%; height:30px; background-color:#FFBABC; " >
<form action="http://search.yaolan.com/luntan/ss.jsp" method="get" target="_blank">
<div style="width:205px; height:21px; margin:5px 0 0 15px; float:left;">
<select name="searchfw">
<option value="0" selected="selected">全部</option>
<option value="1">主題</option>
<option value="2">作者</option>
</select>
<input name="searchword" id="searchword" onmouseover="this.select();" onkeydown="checkKey(event, document.getElementById('lnkSearch'))" type="text" style="width:102px; " />
<input value="" type="Submit" class="dzwc_b1" />
</div>
<span style=" height:30px; line-height:30px; float:left;">
</span>
</form>

</div>

<style type="text/css">
.defaultpost { height: auto !important; height:120px; min-height:120px !important; }
</style>

<script src="include/javascript/viewthread.js" type="text/javascript"></script>
<script type="text/javascript">zoomstatus = parseInt(1);</script>

<div id="infosidemain">

<div id="foruminfo">
<div id="nav">
<div class="userinfolist">
<p style="font-size:14px;"><a href="index.html" id="forumlist" onmouseover="showMenu(this.id)" class="dropmenu">搖籃論壇</a> » <a href="board_24.aspx">女人心情</a> » 合租女孩洗澡不關門,用手機拍了幾張相片。。【好圖共賞】</p>
</div>
</div>
<div id="headsearch">
</div>
</div>

<div id="ad_text"></div>
<div class="pages_btns">
<div class="threadflow"><a href="redirect.php?fid=24&tid=51269126&goto=nextoldset"> ‹‹ 上一主題</a> | <a href="redirect.php?fid=24&tid=51269126&goto=nextnewset">下一主題 ››</a></div>
<div class="pages"><em>44</em><strong>1</strong><a href="thread_51269126_2.aspx" >2</a><a href="thread_51269126_2.aspx" class="next">››</a></div> <a href="#tobottom" style="float:right;margin:10px 0 0 10px; color:#666666; text-decoration:underline">到樓底</a>
<span class="postbtn" id="newspecial" onmouseover="$('newspecial').id = 'newspecialtmp';this.id = 'newspecial';showMenu(this.id)"><a target="_blank" href="post.php?action=newthread&fid=24&extra="><img src="images/default/newtopic.gif" border="0" alt="發新話題" title="發新話題" /></a></span>
<span class="replybtn"><a href="post.php?action=reply&fid=24&tid=51269126&extra="><img src="images/default/reply.gif" border="0" alt="" /></a></span></div>

<ul class="popupmenu_popup newspecialmenu" id="newspecial_menu" style="display: none">
<li><a target="_blank" href="post.php?action=newthread&fid=24&extra=">發新話題</a></li>
<li class="poll"><a target="_blank" href="post.php?action=newthread&fid=24&extra=&special=1">發布投票</a></li> <li class="trade"><a target="_blank" href="post.php?action=newthread&fid=24&extra=&special=2">發布商品</a></li> <li class="reward"><a target="_blank" href="post.php?action=newthread&fid=24&extra=&special=3">發布懸賞</a></li> <li class="activity"><a target="_blank" href="post.php?action=newthread&fid=24&extra=&special=4">發布活動</a></li> <li class="debate"><a target="_blank" href="post.php?action=newthread&fid=24&extra=&special=5">發布辯論</a></li> <li class="video"><a target="_blank" href="post.php?action=newthread&fid=24&extra=&special=6">發布視頻</a></li> </ul>

<form method="post" name="modactions">
<input type="hidden" name="formhash" value="7150568c" />
<div class="mainbox viewthread " style=" background:url(images/default/bbs_bg7.gif) repeat-x top" >
<span class="headactions">

</span>
<h1><span class="kv_threadtitle">[主題]<a href="forumdisplay.php?fid=24&filter=type&typeid=48">[家長里短]</a> 合租女孩洗澡不關門,用手機拍了幾張相片。。【好圖共賞】</span>
</h1>
<table id="pid51598839" summary="pid51598839" cellspacing="0" cellpadding="0">
<tr>
<td class="postauthor">

<div class="online" >

<cite>

<a href="http://space.yaolan.com/50036303" target="_blank" id="userinfo51598839" class="dropmenu" onmouseover="showMenu(this.id)">狂戰</a>

<em>其它</em>

</cite>
</div>

<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td valign="top" >
<b style="color:#009900;width:100px;display:block">新生搖精</b>
<a href="http://space.yaolan.com/50036303" target="_blank" >
<a border="0" target="_blank" href="http://space.yaolan.com/50036303"><img src="/uc/images/noavatar_middle.gif" onerror="this.onerror=null;this.src='/uc/images/noavatar_middle.gif'" width="90" height="90"></a>
</a>
<br/>
<a href="http://space.yaolan.com/50036303" target="_blank" border="0"><img src="/images/headpng/head_1_0_0.png" /></a>
<p style="text-align:center;"><a href="http://www.yaolan.com/help/article2007_462561627026.shtml" target="_blank" border="0"><font color="#ff6600" style="font-size:12px;" >新生搖精</font></a></p>

</td>
<td >

<a name="newpost"></a>
<!-- <p><img src="images/default/star_level1.gif" alt="Rank: 1" /></p>-->
<ul>
<li></li>
<li class="pm"><a href="http://my.yaolan.com/Message/NewWriteMessage.aspx?u=50036303" target="_blank">短消息</a></li>
<li class="buddy"><a href="http://space.yaolan.com/50036303/friends/addfriend.html" target="_blank">加好友</a></li>
<li class="space"><a href="http://space.yaolan.com/50036303/BBS" target="_blank">帖子集</a></li>
</ul>

<DIV style="margin:25px 0 0 5px;color:#999">活力: 192</DIV>
<DIV style="margin:0 0 0 5px;color:#999">魅力: 100</DIV>
<DIV style="margin:0 0 0 5px;color:#999">文采: 102</DIV>

</td>

</tr>
</table>
</td>

<td class="postcontent">
<div class="postinfo" style="background:#FFD8D9">
<strong>1<sup>#</sup></strong>

<em title="復制帖子鏈接到剪貼板" id="postnum51598839" onclick="set('http://bbs.yaolan.com/viewthread.php?tid=51269126&page=1#pid51598839', '帖子鏈接已經復制到剪貼板')"><a href="#">復制本樓地址</a></em>

<em><a href="viewthread.php?tid=51269126&page=1&authorid=50036303" rel="nofollow">只看該作者</a></em>

發表於 2009-3-16 14:40 瀏覽:532 回復:43

</div>
<div id="ad_thread2_0"></div> <div class="postmessage defaultpost" style="background:#FFFFFF">
<div id="ad_thread3_0"></div><div id="ad_thread4_0"></div>

<div id="postmessage_51598839" class="t_msgfont" style="padding:10px;"><img src="http://www.funbq.com/img/216/bq51551475.jpg" border="0" onclick="zoom(this, this.src)" onload="attachimg(this, 'load')" alt="" /><br />
一、此貼為調查貼,為配合公安部第二次全國色狼普查實名登記制,特發此貼,被標題吸引進入瀏覽的,不論男女,皆為色狼. <br />
<br />
二、帖子被瀏覽數即為色狼數量,統計結果截止到2009年8月31日. <br />
<br />
三、瀏覽此貼時,系統已自動記錄瀏覽者的ip地址以及論壇id,請勿抱有僥幸心理. <br />
<br />
四、不要說沒看清或點錯了之類的鬼話來為自己辯解 <br />
<br />
五、請於觀看此貼20日內與戶口所在地街道辦事處或派出所自帶小板凳聯系備案 <br />
<br />
六、此次調查結果將於2009年中在各地方電視台滾動播出,敬請期待。。。。。。。。<br />
<br />
[<i> 本帖最後由 狂戰 於 2009-3-16 15:17 編輯 </i>]</div>

㈢ 什麼是H1、H2和H3標簽

heading是h1,h2,h3,h4,h5,h6 這六個Xhtml標簽的統稱,既標題的意思。六個標簽的權重由大到小,既h1為大標題,h6為最小的標題。h1 — 大標題,放置於首頁頂部區域,通常即導航以上的部分,全站通用,用來詮釋整個網站的內容,應包含網站主關鍵字,但切忌不要進行關鍵字堆砌。最好是在網頁源代碼的body標簽一開始的第一個容器中第一行出現。且保證一個頁面中只出現一次。h2 — 副標題,每個頁面出現的次數以1-3次為宜。首頁:同h1,放置於主頭部區域,於h1的下方,全站調用,同樣用於概括整站的內容。或者在頭部通用區域的下方,首頁內容的開頭或者中間部分使用一次,用於詮釋首頁的內容。子頻道頁:無論頂部區域是否出現過一次h2,可結合實際情況在頭部通用區域的下方,頁面內容的開頭部分使用一次,用於詮釋頻道頁面的內容。(以上2種方法可以任選其一,也可以同時並存)文章/產品內頁:文章的標題使用h2標簽。按以上方法,h2標簽最多會被使用到3次,但是請少使用1次。據以往經驗來看,文章/產品內頁使用h2標簽效果顯著。h3— 小標題,個人愛用於小欄目的名稱

㈣ 請教C語言各種數值排序的源碼。冒泡、插入等等

================================================
功能:選擇排序
輸入:數組名稱(也就是數組首地址)、數組中元素個數
================================================
*/
/*
====================================================
演算法思想簡單描述:
在要排序的一組數中,選出最小的一個數與第一個位置的數交換;
然後在剩下的數當中再找最小的與第二個位置的數交換,如此循環
到倒數第二個數和最後一個數比較為止。
選擇排序是不穩定的。演算法復雜度O(n2)--[n的平方]
=====================================================
*/
void select_sort(int *x, int n)
{
int i, j, min, t;
for (i=0; i <n-1; i++) /*要選擇的次數:0~n-2共n-1次*/
{
min = i; /*假設當前下標為i的數最小,比較後再調整*/
for (j=i+1; j <n; j++)/*循環找出最小的數的下標是哪個*/
{
if (*(x+j) < *(x+min))
{
min = j; /*如果後面的數比前面的小,則記下它的下標*/
}
}
if (min != i) /*如果min在循環中改變了,就需要交換數據*/
{
t = *(x+i);
*(x+i) = *(x+min);
*(x+min) = t;
}
}
}
/*
================================================
功能:直接插入排序
輸入:數組名稱(也就是數組首地址)、數組中元素個數
================================================
*/
/*
====================================================
演算法思想簡單描述:
在要排序的一組數中,假設前面(n-1) [n>=2] 個數已經是排
好順序的,現在要把第n個數插到前面的有序數中,使得這n個數
也是排好順序的。如此反復循環,直到全部排好順序。
直接插入排序是穩定的。演算法時間復雜度O(n2)--[n的平方]
=====================================================
*/
void insert_sort(int *x, int n)
{
int i, j, t;
for (i=1; i <n; i++) /*要選擇的次數:1~n-1共n-1次*/
{
/*
暫存下標為i的數。注意:下標從1開始,原因就是開始時
第一個數即下標為0的數,前面沒有任何數,單單一個,認為
它是排好順序的。
*/
t=*(x+i);
for (j=i-1; j>=0 && t <*(x+j); j--) /*注意:j=i-1,j--,這里就是下標為i的數,在它前面有序列中找插入位置。*/
{
*(x+j+1) = *(x+j); /*如果滿足條件就往後挪。最壞的情況就是t比下標為0的數都小,它要放在最前面,j==-1,退出循環*/
}
*(x+j+1) = t; /*找到下標為i的數的放置位置*/
}
}
/*
================================================
功能:冒泡排序
輸入:數組名稱(也就是數組首地址)、數組中元素個數
================================================
*/
/*
====================================================
演算法思想簡單描述:
在要排序的一組數中,對當前還未排好序的范圍內的全部數,自上
而下對相鄰的兩個數依次進行比較和調整,讓較大的數往下沉,較
小的往上冒。即:每當兩相鄰的數比較後發現它們的排序與排序要
求相反時,就將它們互換。
下面是一種改進的冒泡演算法,它記錄了每一遍掃描後最後下沉數的
位置k,這樣可以減少外層循環掃描的次數。
冒泡排序是穩定的。演算法時間復雜度O(n2)--[n的平方]
=====================================================
*/
void bubble_sort(int *x, int n)
{
int j, k, h, t;
for (h=n-1; h>0; h=k) /*循環到沒有比較范圍*/
{
for (j=0, k=0; j <h; j++) /*每次預置k=0,循環掃描後更新k*/
{
if (*(x+j) > *(x+j+1)) /*大的放在後面,小的放到前面*/
{
t = *(x+j);
*(x+j) = *(x+j+1);
*(x+j+1) = t; /*完成交換*/
k = j; /*保存最後下沉的位置。這樣k後面的都是排序排好了的。*/
}
}
}
}
================================================
功能:希爾排序
輸入:數組名稱(也就是數組首地址)、數組中元素個數
================================================
*/
/*
====================================================
演算法思想簡單描述:
在直接插入排序演算法中,每次插入一個數,使有序序列只增加1個節點,
並且對插入下一個數沒有提供任何幫助。如果比較相隔較遠距離(稱為
增量)的數,使得數移動時能跨過多個元素,則進行一次比較就可能消除
多個元素交換。D.L.shell於1959年在以他名字命名的排序演算法中實現
了這一思想。演算法先將要排序的一組數按某個增量d分成若干組,每組中
記錄的下標相差d.對每組中全部元素進行排序,然後再用一個較小的增量
對它進行,在每組中再進行排序。當增量減到1時,整個要排序的數被分成
一組,排序完成。
下面的函數是一個希爾排序演算法的一個實現,初次取序列的一半為增量,
以後每次減半,直到增量為1。
希爾排序是不穩定的。
=====================================================
*/
void shell_sort(int *x, int n)
{
int h, j, k, t;
for (h=n/2; h>0; h=h/2) /*控制增量*/
{
for (j=h; j <n; j++) /*這個實際上就是上面的直接插入排序*/
{
t = *(x+j);
for (k=j-h; (k>=0 && t <*(x+k)); k-=h)
{
*(x+k+h) = *(x+k);
}
*(x+k+h) = t;
}
}
}
/*
================================================
功能:快速排序
輸入:數組名稱(也就是數組首地址)、數組中起止元素的下標
================================================
*/
/*
====================================================
演算法思想簡單描述:
快速排序是對冒泡排序的一種本質改進。它的基本思想是通過一趟
掃描後,使得排序序列的長度能大幅度地減少。在冒泡排序中,一次
掃描只能確保最大數值的數移到正確位置,而待排序序列的長度可能只
減少1。快速排序通過一趟掃描,就能確保某個數(以它為基準點吧)
的左邊各數都比它小,右邊各數都比它大。然後又用同樣的方法處理
它左右兩邊的數,直到基準點的左右只有一個元素為止。它是由
C.A.R.Hoare於1962年提出的。
顯然快速排序可以用遞歸實現,當然也可以用棧化解遞歸實現。下面的
函數是用遞歸實現的,有興趣的朋友可以改成非遞歸的。
快速排序是不穩定的。最理想情況演算法時間復雜度O(nlog2n),最壞O(n2)
=====================================================
*/
void quick_sort(int *x, int low, int high)
{
int i, j, t;
if (low < high) /*要排序的元素起止下標,保證小的放在左邊,大的放在右邊。這里以下標為low的元素為基準點*/
{
i = low;
j = high;
t = *(x+low); /*暫存基準點的數*/
while (i <j) /*循環掃描*/
{
while (i <j && *(x+j)>t) /*在右邊的只要比基準點大仍放在右邊*/
{
j--; /*前移一個位置*/
}
if (i <j)
{
*(x+i) = *(x+j); /*上面的循環退出:即出現比基準點小的數,替換基準點的數*/
i++; /*後移一個位置,並以此為基準點*/
}
while (i <j && *(x+i) <=t) /*在左邊的只要小於等於基準點仍放在左邊*/
{
i++; /*後移一個位置*/
}
if (i <j)
{
*(x+j) = *(x+i); /*上面的循環退出:即出現比基準點大的數,放到右邊*/
j--; /*前移一個位置*/
}
}
*(x+i) = t; /*一遍掃描完後,放到適當位置*/
quick_sort(x,low,i-1); /*對基準點左邊的數再執行快速排序*/
quick_sort(x,i+1,high); /*對基準點右邊的數再執行快速排序*/
}
}
/*
================================================
功能:堆排序
輸入:數組名稱(也就是數組首地址)、數組中元素個數
================================================
*/
/*
====================================================
演算法思想簡單描述:
堆排序是一種樹形選擇排序,是對直接選擇排序的有效改進。
堆的定義如下:具有n個元素的序列(h1,h2,...,hn),當且僅當
滿足(hi>=h2i,hi>=2i+1)或(hi <=h2i,hi <=2i+1)(i=1,2,...,n/2)
時稱之為堆。在這里只討論滿足前者條件的堆。
由堆的定義可以看出,堆頂元素(即第一個元素)必為最大項。完全二叉樹可以
很直觀地表示堆的結構。堆頂為根,其它為左子樹、右子樹。
初始時把要排序的數的序列看作是一棵順序存儲的二叉樹,調整它們的存儲順序,
使之成為一個堆,這時堆的根節點的數最大。然後將根節點與堆的最後一個節點
交換。然後對前面(n-1)個數重新調整使之成為堆。依此類推,直到只有兩個節點
的堆,並對它們作交換,最後得到有n個節點的有序序列。
從演算法描述來看,堆排序需要兩個過程,一是建立堆,二是堆頂與堆的最後一個元素
交換位置。所以堆排序有兩個函數組成。一是建堆的滲透函數,二是反復調用滲透函數
實現排序的函數。
堆排序是不穩定的。演算法時間復雜度O(nlog2n)。
*/
/*
功能:滲透建堆
輸入:數組名稱(也就是數組首地址)、參與建堆元素的個數、從第幾個元素開始
*/
void sift(int *x, int n, int s)
{
int t, k, j;
t = *(x+s); /*暫存開始元素*/
k = s; /*開始元素下標*/
j = 2*k + 1; /*右子樹元素下標*/
while (j <n)
{
if (j <n-1 && *(x+j) < *(x+j+1))/*判斷是否滿足堆的條件:滿足就繼續下一輪比較,否則調整。*/
{
j++;
}
if (t <*(x+j)) /*調整*/
{
*(x+k) = *(x+j);
k = j; /*調整後,開始元素也隨之調整*/
j = 2*k + 1;
}
else /*沒有需要調整了,已經是個堆了,退出循環。*/
{
break;
}
}
*(x+k) = t; /*開始元素放到它正確位置*/
}
/*
功能:堆排序
輸入:數組名稱(也就是數組首地址)、數組中元素個數
*/
void heap_sort(int *x, int n)
{
int i, k, t;
int *p;
for (i=n/2-1; i>=0; i--)
{
sift(x,n,i); /*初始建堆*/
}
for (k=n-1; k>=1; k--)
{
t = *(x+0); /*堆頂放到最後*/
*(x+0) = *(x+k);
*(x+k) = t;
sift(x,k,0); /*剩下的數再建堆*/
}
}
void main()
{
#define MAX 4
int *p, i, a[MAX];
/*錄入測試數據*/
p = a;
printf("Input %d number for sorting :\n",MAX);
for (i=0; i <MAX; i++)
{
scanf("%d",p++);
}
printf("\n");

㈤ h2資料庫在linux伺服器怎麼使用

簡單來說就是用jdbc:h2:mem:h2db來建立內存模式,並建表, 然後jdbc:h2:tcp://192.168.20.141:8082/mem:h2db來訪問上面的內存資料庫 package test; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; imp...

㈥ 問一個入門簡單的JS問題,代碼如下,謝謝

這是Html標簽,<h>是headline的縮寫 是標題的意思一共有6個等級h1 ,h2,h3,h4,h5,h6 循環著剛剛循環出這個6種標簽等級, 你的猜測是沒有錯的,它的源碼確實是 「<h1>這是標題1</h1>」但是瀏覽器解析這段源代碼的時候 ,就會把<h1>解析掉 不會直接顯示在網頁中.而<h1></h1>中間的文字就會按照標題1的規格顯示 / 這個斜杠就是結束的意思

熱點內容
怎麼設置電腦開機密碼和屏幕鎖 發布:2025-05-16 03:07:05 瀏覽:55
華為鎖屏密碼忘記了怎麼解鎖 發布:2025-05-16 03:06:26 瀏覽:474
安卓文字為什麼沒有蘋果舒服 發布:2025-05-16 03:01:26 瀏覽:357
phpnow解壓版 發布:2025-05-16 02:52:49 瀏覽:811
dmporacle資料庫 發布:2025-05-16 02:44:31 瀏覽:831
雲主機上傳 發布:2025-05-16 02:44:30 瀏覽:82
滑鼠如何編程 發布:2025-05-16 02:29:09 瀏覽:816
安卓70能用什麼軟體 發布:2025-05-16 01:45:09 瀏覽:481
編程發展史 發布:2025-05-16 01:38:52 瀏覽:529
android圖片氣泡 發布:2025-05-16 01:38:40 瀏覽:887