?? 1.cpp
字號:
#include "head.h"
//創建線性表
//(1.1)先進先出函數-----含表頭結點-----'0'為結束符
link creat11() //“link” 為前面定義的結構類型指針
{
link head,tail,p;
int e;
head=(link)malloc (LENG3); //生成表頭結點
head->next=NULL; //置為空表
tail=head; //尾指針指向表頭
scanf("%d",&e); //輸入第一個數
while(e) //不為0
{
p=(link)malloc(LENG3); //生成新結點
p->data=e; //裝入輸入的元素e
tail->next=p; //新結點鏈接到表尾
tail=p; //尾指針指向新結點
scanf("%d",&e); //輸入第二個數
}
tail->next=NULL; //尾結點的next置為空指針
return head; //返回頭指針
}
//(1.2)先進后出函數-----含表頭結點-----'0'為結束符
link creat12( ) //“link” 為前面定義的結構類型指針
{
link head,p;
int e;
head=(link)malloc(LENG3); //生成表頭結點
head->next=NULL; //置為空表
scanf("%d",&e); //輸入第一個數
while(e) //不為0
{
p=(link)malloc(LENG3); //生成新結點
p->data=e; //輸入數送新結點的data
p->next=head->next; //新結點指針指向原首結點
head->next=p; //表頭結點的指針指向新結點
scanf("%d",&e); //輸入第二個數
}
return head; //返回頭指針
}
//(1.3)生成帶頭結點的遞增有序單鏈表函數。(不包括0)
link creat13()
{
link head,p,q,f;
int e;
head=(link)malloc(LENG3); //生成表頭結點
head->next=NULL; //置為空表
scanf("%d",&e); //輸入整數
while (e) //不為 0,未結束
{
q=head;
p=head->next; //q,p掃描,查找插入位置
while(p&&e>p->data) //未掃描完,且e大于當前結點
{
q=p;
p=p->next; //q,p后移,查下一個位置
}
f=(link)malloc(LENG3); //生成新結點
f->data=e; //裝入元素e
f->next=p; //插入新結點
scanf("%d",&e); //輸入整數
}
return head;
}
void main1(h_list &lead)
{
int choice=1;
static int i; //用靜態就是為了保留i的值
h_table tab;
while (choice!=0)
{
tab=(h_table)malloc(LENG2);
printf(" //////////////////////////////////////\n");
printf(" // 請輸入數字 0 到 4 選擇: //\n");
printf(" // 1. 先進先出表 //\n");
printf(" // 2. 先進后出表 //\n");
printf(" // 3. 有序表 //\n");
printf(" // 0. 退出程序!!! //\n");
printf(" // 請輸入你的選擇: //\n");
printf(" //////////////////////////////////////\n");
scanf("%d",&choice);
system("cls");
switch (choice)
{
case 1: tab->type=choice;
printf("請輸入鏈表名字:");
scanf("%s",tab->name);
printf("請輸入數據:\n");
tab->tou=creat11();
lead->assistant[i++]=tab;
lead->length=i;
break;
case 2: tab->type=choice;
printf("請輸入鏈表名字:");
scanf("%s",tab->name);
printf("請輸入數據:\n");
tab->tou=creat12();
lead->assistant[i++]=tab;
lead->length=i;
break;
case 3: tab->type=choice;
printf("請輸入鏈表名字:");
scanf("%s",tab->name);
printf("請輸入數據:\n");
tab->tou=creat13();
lead->assistant[i++]=tab;
lead->length=i;
break;
case 0: break;
default: printf("輸入錯誤!!!\n");
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -