一、迴圈雙向鏈結表
-
插入元素
int insert(DList *L, ElemType e) { Link current = L->head; Link previous = L->tail; Link newNode; int size = getSize(*L); int position=0; if (current==NULL) { // Case 1:當迴圈雙向鏈結表為空時。 newNode = (Link) malloc(sizeof(Node)); newNode->elem = e; newNode->prev = newNode; newNode->next = newNode; L->head = newNode; L->tail = newNode; return position; } for (position=0; position<size; position++) { if (current->elem>=e) break; previous = current; current = current->next; } // Cases 2, 3 & 4: 插入一個節點的 current 之前。 newNode = (Link) malloc(sizeof(Node)); newNode->elem = e; newNode->prev = previous; previous->next = newNode; newNode->next = current; current->prev = newNode; if (position==0) L->head = newNode; else if (position==size) L->tail = newNode; return position; // 返回位置。
-
刪除元素
int delete(DList *L, ElemType e) { Link current = L->head; Link previous = L->tail; int position = 0; if (current==NULL) return -1; do 。 if (current->elem==e) { if (position==0) { if (current->next==current) { L->head = NULL; L->tail = NULL; }else { previous->next = current->next; current->next->prev = previous; L->head = current->next; } free(current); return position; } else { if (current->next==L->head) // 刪除的是尾節點。 L->tail = previous; previous->next = current->next; current->next->prev = previous; free(current); return position; } } else if (current->elem<e) { // 檢查下一個節點。 previous = current; current = current->next; position++; } else return -1; // 目前節點資料已超過刪除的值;刪除失敗。 } while (current!=L->head); return -1; // current 回到頭節點,刪除失敗。 }
二、火車瀏覽器的運用
-
XPath應用
-
sqlite資料庫應用
建立語句:create table 檔名(要開啟的迴圈文字變數 integer primary key,表頭1,表頭2...)
插入資料語句:insert into 檔名(表頭1,表頭2...)values('{文字變數1}','{文字變數2}')
三、js入門練習
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title></title> </head> <body> <script type="text/javascript"> var num =57; if ((num-7)%10==0 || parseInt(num/7)==0) console.log("這不是安全數"); else console.log ("這是安全數"); var i,j,k; var a=''; for(i=1;i<10;i++){ for(j=1;j<=i;j++){ a+=i+'*'+j+'='+parseInt(i*j)+' '; } a+='\n'; } console.log(a); </script> </body> </html>
執行結果: