#include <stdlib.h>
#include<stdio.h>
#include <malloc.h>
#define stack_init_size 100
#define stackincrement 10
typedef struct sqstack
{
int *base;
int *top;
int stacksize;
} sqstack;
int StackInit(sqstack *s)
{
s->base=(int *)malloc(stack_init_size *sizeof(int));
if(!s->base)
return 0;
s->top=s->base;
s->stacksize=stack_init_size;
return 1;
}
int Push(sqstack *s,int e)
{
if(s->top-s->base>=s->stacksize)
{
s->base=(int *)realloc(s->base,(s->stacksize+stackincrement)*sizeof(int)); if(!s->base)
return 0;
s->top=s->base+s->stacksize;
s->stacksize+=stackincrement;
}
*(s->top++)=e;
return e;
}
int pop(sqstack *s,int e)
{
if(s->top==s->base)
return 0;
e=*--s->top;
return e;
}
int stackempty(sqstack *s)
{
if(s->top==s->base)
{
return 1;
}
else
{
return 0;
}
}
int conversion(sqstack *s)
{
int n,e=0,flag=0;
printf("輸入要轉化的十進制數:\n");
scanf("%d",&n);
printf("要轉化為多少進制:\n"); scanf("%d",&flag);
printf("將十進制數%d 轉化為%d 進制是:\n",n,flag);
while(n)
{
Push(s,n%flag);
n=n/flag;
}
while(!stackempty(s))
{
e=pop(s,e);
switch(e)
{
case 10: printf("A");
break;
case 11: printf("B");
break;
case 12: printf("C"); break;
case 13: printf("D"); break;
case 14: printf("E"); break;
case 15: printf("F"); break;
default: printf("%d",e); }
}
printf("\n");
return 0;
}
int main()
{
sqstack s;
StackInit(&s);
conversion(&s);
return 0;
}
標簽:
整數
棧
基本操作
十進制
轉化
進制
上傳時間:
2016-12-08
上傳用戶:愛你198
#include <iostream>
#include <stdio.head>
#include <stdlib.head>
#include <string.head>
#define ElemType int
#define max 100
using namespace std;
typedef struct node1
{
ElemType data;
struct node1 *next;
}Node1,*LinkList;//鏈棧
typedef struct
{
ElemType *base;
int top;
}SqStack;//順序棧
typedef struct node2
{
ElemType data;
struct node2 *next;
}Node2,*LinkQueue;
typedef struct node22
{
LinkQueue front;
LinkQueue rear;
}*LinkList;//鏈隊列
typedef struct
{
ElemType *base;
int front,rear;
}SqQueue;//順序隊列
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
//1.采用鏈式存儲實現棧的初始化、入棧、出棧操作。
LinkList CreateStack()//創建棧
{
LinkList top;
top=NULL;
return top;
}
bool StackEmpty(LinkList s)//判斷棧是否為空,0代表空
{
if(s==NULL)
return 0;
else
return 1;
}
LinkList Pushead(LinkList s,int x)//入棧
{
LinkList q,top=s;
q=(LinkList)malloc(sizeof(Node1));
q->data=x;
q->next=top;
top=q;
return top;
}
LinkList pop(LinkList s,int &e)//出棧
{
if(!StackEmpty(s))
{
printf("棧為空。");
}
else
{
e=s->data;
LinkList p=s;
s=s->next;
free(p);
}
return s;
}
void DisplayStack(LinkList s)//遍歷輸出棧中元素
{
if(!StackEmpty(s))
printf("棧為空。");
else
{
wheadile(s!=NULL)
{
cout<<s->data<<" ";
s=s->next;
}
cout<<endl;
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
//2.采用順序存儲實現棧的初始化、入棧、出棧操作。
int StackEmpty(int t)//判斷棧S是否為空
{
SqStack.top=t;
if (SqStack.top==0)
return 0;
else return 1;
}
int InitStack()
{
SqStack.top=0;
return SqStack.top;
}
int pushead(int t,int e)
{
SqStack.top=t;
SqStack.base[++SqStack.top]=e;
return SqStack.top;
}
int pop(int t,int *e)//出棧
{
SqStack.top=t;
if(!StackEmpty(SqStack.top))
{
printf("棧為空.");
return SqStack.top;
}
*e=SqStack.base[s.top];
SqStack.top--;
return SqStack.top;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
//3.采用鏈式存儲實現隊列的初始化、入隊、出隊操作。
LinkList InitQueue()//創建
{
LinkList head;
head->rear=(LinkQueue)malloc(sizeof(Node));
head->front=head->rear;
head->front->next=NULL;
return head;
}
void deleteEle(LinkList head,int &e)//出隊
{
LinkQueue p;
p=head->front->next;
e=p->data;
head->front->next=p->next;
if(head->rear==p) head->rear=head->front;
free(p);
}
void EnQueue(LinkList head,int e)//入隊
{
LinkQueue p=(LinkQueue)malloc(sizeof(Node));
p->data=e;
p->next=NULL;
head->rear->next=p;
head->rear=p;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
//4.采用順序存儲實現循環隊列的初始化、入隊、出隊操作。
bool InitQueue(SqQueue &head)//創建隊列
{
head.data=(int *)malloc(sizeof(int));
head.front=head.rear=0;
return 1;
}
bool EnQueue(SqQueue &head,int e)//入隊
{
if((head.rear+1)%MAXQSIZE==head.front)
{
printf("隊列已滿\n");
return 0;
}
head.data[head.rear]=e;
head.rear=(head.rear+1)%MAXQSIZE;
return 1;
}
int QueueLengthead(SqQueue &head)//返回隊列長度
{
return (head.rear-head.front+MAXQSIZE)%MAXQSIZE;
}
bool deleteEle(SqQueue &head,int &e)//出隊
{
if(head.front==head.rear)
{
cout<<"隊列為空!"<<endl;
return 0;
}
e=head.data[head.front];
head.front=(head.front+1)%MAXQSIZE;
return 1;
}
int gethead(SqQueue head)//得到隊列頭元素
{
return head.data[head.front];
}
int QueueEmpty(SqQueue head)//判斷隊列是否為空
{
if (head.front==head.rear)
return 1;
else
return 0;
}
void travelQueue(SqQueue head)//遍歷輸出
{
wheadile(head.front!=head.rear)
{
printf("%d ",head.data[head.front]);
head.front=(head.front+1)%MAXQSIZE;
}
cout<<endl;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
//5.在主函數中設計一個簡單的菜單,分別測試上述算法。
int main()
{
LinkList top=CreateStack();
int x;
wheadile(scanf("%d",&x)!=-1)
{
top=Pushead(top,x);
}
int e;
wheadile(StackEmpty(top))
{
top=pop(top,e);
printf("%d ",e);
}//以上是鏈棧的測試
int top=InitStack();
int x;
wheadile(cin>>x)
top=pushead(top,x);
int e;
wheadile(StackEmpty(top))
{
top=pop(top,&e);
printf("%d ",e);
}//以上是順序棧的測試
LinkList Q;
Q=InitQueue();
int x;
wheadile(scanf("%d",&x)!=-1)
{
EnQueue(Q,x);
}
int e;
wheadile(Q)
{
deleteEle(Q,e);
printf("%d ",e);
}//以上是鏈隊列的測試
SqQueue Q1;
InitQueue(Q1);
int x;
wheadile(scanf("%d",&x)!=-1)
{
EnQueue(Q1,x);
}
int e;
wheadile(QueueEmpty(Q1))
{
deleteEle(Q1,e);
printf("%d ",e);
}
return 0;
}
標簽:
數據結構
實驗
上傳時間:
2018-05-09
上傳用戶:123456..
軟件說明: 使用方法:(同BMP2PCB,只能導入黑白BMP文件.)關于比例:方法1) 對于經過圖像處理軟件處理過的BMP文件,由于比例已改變,可以先在PROTEL99SE的PCB里 按PCB實物大小畫好KEEP層的外框,以便確定板大小, Place Graphics Options選項中,Placement Mode設置為Placement Rectang; 導入BMP時,圖片的起點定位KEEP外框的左下角,終點定位在KEEP外框的右上角即可.方法2) 對于1:1掃描BMP文件,設置選項里,Place Graphics Options選項中, Placement Mode設置為Cursor;Scale設置為3.35;怎樣在中文漢化版里編輯菜單:1. 打開PROTEL99SE,在PCB環境里,點左上角下鍵頭,選擇第二項;2. 點菜單右上角的MENU按鈕,選EDIT;3. 點擊菜單右上角的MENU按鈕,選Expand ALL;4. 在菜單中找到選擇向導 這一項,在其下面點擊右鍵,選ADD(添加);5. 在下面TEXT欄目里修改名成為:Klipper (Y for pop up){Y};6. 在Klipper下面點擊右鍵,選ADD(添加);7. 在下面TEXT欄目里修改成為&Copy to Windows Clipboard,并在PROCES欄目后面 點BROWSE指向Klipper99se:copyToWindowsclipboaed, PARAM欄目里點后面的INFO指向$Description=copy to zhe windows clipboard;8. 重復6,7步驟:依次建立下: 鍵名稱(TEXT): Klipper 以下為子菜單: &Copy to Windows Clipboard ; BROWSE : Klipper99se:copyToWindows clipboaed, PARAM: $Description=copy to zhe windows (復制到WINDOWS剪貼板) &Paste From Windows Clipboard; PROCES: Klipper99se:PasteFromWindowsClipoard; PARAM: $Description=Paste From the Windows Clipoard; (WINDOWS剪貼板粘帖) Place &Graphic; PROCES: Klipper99se:PlaceGraphic; PARAM: $Description=Place Graphic using Klipper; (放置BMP圖片) &Klipper Preferences PROCES: Klipper99se:KlipperPreferences; PARAM: $Description=Klipper Sst up; (設置參數)
標簽:
protel99SE
上傳時間:
2022-07-12
上傳用戶:20125101110