当前位置:首页 » 操作系统 » 算法演示系统

算法演示系统

发布时间: 2022-04-11 13:49:23

A. 设计数据结构相关算法的演示系统。

//顺序表
#include<iostream>
#include<string>
using namespace std;
#define N 100
//主串和子串的输入格式均为$abcdefg...,开始匹配的位置为1(或其他合法位置)匹配结果不包括'$'

int Index_KMP(string& s,string& p,int start_pos)
{
int in=1,jn=0;
int* next=new int[p.length()];
next[1]=0;
while(in<p.length()-1)
{
if(jn==0||p[in]==p[jn]){++in;++jn;next[in]=jn;}
else jn=next[jn];
}
cout<<"子串"<<p<<"的next数组值为:"<<endl;
int i;
for( i=1;i<p.length();i++)
cout<<next[i]<<endl;

i=start_pos;
int j=1;
while(i<=s.length()-1&&j<=p.length()-1)
{if(j==0||s[i]==p[j]){++i;++j;}
else j=next[j];
}
if(j>=p.length()) return i-p.length()+1;
else return 0;
}

typedef struct node
{
char data;
struct node *next;
}link;

link * get(link *l, int i)
{
link *p;int j=0;
p=l;
while((j<i) && (p->next!=NULL))
{p=p->next;j++;}
if(j==i)
return p;
else
return NULL;
}

link * ins (link *l, char ch,int i)
{ link *p,*s;
p=get(l,i-1);
if(p==NULL)
cout<<"输入有误"<<endl;
else
{
s=(link *)malloc(sizeof(link));
s->data=ch;
s->next=p->next;
p->next=s;
}
return l;
}

link * find(link *l, char ch)
{
link *p; int i=0; int j=0;
p=l;

while(p!=NULL)
{ i++;
if(p->data!=ch)
p=p->next;
else {cout<<"您查找的数据在第"<<i-1<<"个位置."<<endl;
j=1;p=p->next;
}

}
if(j!=1)
cout<<"您查找的数据不在线性表中."<<endl;
return l;
}

link * del(link *l, int i)
{
link *p,*s;
p=get(l,i-1);
if(p==NULL)
cout<<"输入有误"<<endl;
else
{
s=p->next;
p->next=s->next;
free(s);
}
return l;
}

link * add(link *l )
{
link *p,*s;
cout<<"请输入一串单字符数据,以*结束!"<<endl;
char ch;
link *HEAD;
link *R,*P,*L;
HEAD=(link *)malloc(sizeof(link));
HEAD->next=NULL;
R=HEAD;
getchar();
ch=getchar();
while(ch!='*')
{
P=(link *)malloc(sizeof(link));
P->data=ch;P->next=NULL;
R->next=P;R=R->next;
getchar();
ch=getchar();

}

L=HEAD;
cout<<"当前输入的线性表为:"<<endl;
P=L;P=P->next;
if(L!=NULL)
do
{cout<<P->data<<" ";
P=P->next;
}while(P!=NULL);
cout<<endl;
p=l;
while(p->next!=NULL)
p=p->next;
s=L;
p->next=s->next;
p=l;
return l;
}

link * print(link *l)
{ int i,k;
char ch;
link *p,*q;
cout<<"当前线性表为:"<<endl;
p=l;p=p->next;
if(l!=NULL)
do
{cout<<p->data<<" ";
p=p->next;
}while(p!=NULL);
cout<<endl;
cout<<" ╔=========================================================╗\n";
cout<<" 链表 \n";
cout<<" ╚=========================================================╝\n";
cout<<" 请选择您要的操作: \n";
cout<<" ╔=========================================================╗\n";
cout<<" * 1、插入 * \n";
cout<<" * 2、查找 * \n";
cout<<" * 3、删除 * \n";
cout<<" * 4、合并 * \n";
cout<<" * 0、退出 * \n";
cout<<" ╚=========================================================╝\n";
cout<<endl;
cin>>k;
if(k==1)
{
cout<<" 请输入您要插入的数据值:";
cin>>ch;
cout<<" 请输入您要插入的位置:";
cin>>i;
p=ins(l,ch,i);
q=print(l);
}
else if(k==2)
{
cout<<" 请输入您要查找的数据值:";
cin>>ch;
p=find(l,ch);
q=print(l);
}
else if(k==3)
{
cout<<" 请输入您要删除的数据的位置:";
cin>>i;
p=del(l,i);
q=print(l);
}
else if(k==4)
{ p=add(l);
q=print(l);
}
else if(k==0)
;
else
{cout<<"输入错误!"<<endl;
q=print(l);}
return l;
}

#define MaxSize 100

typedef int DataType;
class SeqList
{
DataType list[MaxSize];
int length;
public:
SeqList(){length=0;}
void SLCreat(int n);
void SLInsert(int i,DataType x);
void SLDelete(int i);
int GetLength(){return length;}
int SLFind(DataType x);
DataType SLGet(int i);
int SLIsEmpty();
void SLPrint();
};

//创建顺序表
void SeqList::SLCreat(int n)
{
DataType x;
cout << "请输入数据元素:";
for (int i=0;i<n;i++){
cin >>x;
list[i]=x;
length++;
}
}

//在顺序表L中的i位置插入数据元素x
void SeqList::SLInsert(int i,DataType x)
{
int k;
if (length>=MaxSize)
cout<< "表已满,无法插入!"<<endl;
else if (i<0||i>length)
cout <<"参数i不合理!" <<endl;
else
{
for (k=length;k>i;k--)
{list[k]=list[k-1];}
list[i]=x;
length++;
}
}

//删除第i个位置的数据元素
void SeqList::SLDelete(int i)
{
int k;
if (!SLIsEmpty())
cout << "表已空,无法删除!"<<endl;
else if (i<0||i>length)
cout << "参数i不合理!"<<endl;
else
{
for (k=i-1;k<length;k++)
list[k]=list[k+1];
length--;
}
}

//查找数据元素x在表中的位置
int SeqList::SLFind(DataType x)
{
int i=0;
while (i<length&&list[i]!=x) i++;
if (i>=length) return -1;
else return i+1;
}

//获取第i个位置的元素的数值
DataType SeqList::SLGet(int i)
{
if (i<0||i>length)
{
cout<<"参数i不合理!"<<endl;
return 0;
}
else
return list[i-1];
}

//判断顺序表是否为空
int SeqList::SLIsEmpty()
{
if (length<=0) return 0;
else return 1;
}

//奖顺序表显示在屏幕上
void SeqList::SLPrint()
{
if (!SLIsEmpty())
cout<<"空表!"<<endl;
else
for (int i=0;i<length;i++)
cout<<list[i]<<" ";
cout <<endl;
}

int main()
{
int select;
char Continue='Y';
while(Continue=='Y')
{
cout<<" ╔=========================================================╗\n";
cout<<" 数据结构演示系统 \n";
cout<<" ╚=========================================================╝\n";
cout<<" 请选择操作: \n";
cout<<" ╔=========================================================╗\n";
cout<<" * 1.顺序表操作 * \n";
cout<<" * 2.链表操作 * \n";
cout<<" * 3.字符串匹配 * \n";
cout<<" ╚=========================================================╝\n";
cout<<endl;
cin>>select;
switch(select)
{
case 1:
{
SeqList myList;
int i,n,flag=1,select1;
DataType x;
cout<<" ╔=========================================================╗\n";
cout<<" 顺序表 \n";
cout<<" =========================================================== \n";
cout<<" * 1、建立顺序表 * \n";
cout<<" * 2、求第i个位置上的数值 * \n";
cout<<" * 3、求x数值的位置: * \n";
cout<<" * 4、在第i个位置插入数值元素x * \n";
cout<<" * 5、删除第i个位置上的数值 * \n";
cout<<" * 6、退出 * \n";
cout<<" ╚=========================================================╝\n";
cout<<endl;
while (flag)
{
cout<<"请选择操作: ";
cin>>select1;
switch(select1)
{
case 1:
cout<<"请输入顺序表的长度: ";
cin>>n;
myList.SLCreat(n);
cout<<"你所输入的顺序表为: ";
myList.SLPrint();
break;
case 2:
cout<<"请输入i的位置: ";
cin>>i;
cout<<"第"<<i<<"个位置上的数值为: "<<myList.SLGet(i)<<endl;
break;
case 3:
cout<<"请输入x的值: ";
cin>>x;
i=myList.SLFind(x);
if(i!=-1) cout<<"x的位置为: "<<i<<endl;
else cout<<"没有找到!";
break;
case 4:
cout<<"请输入要插入的元素的位置i和数值x: ";
cin>>i>>x;
myList.SLInsert(i,x);
cout<<"插入后的顺序表为: ";
myList.SLPrint();
break;
case 5:
cout<<"请输入要删除的元素的位置: ";
cin>>i;
myList.SLDelete(i);
cout<<"删除后的顺序表为: ";
myList.SLPrint();
break;
case 6:
flag=0;
//break;
}
}
}
break;

case 2:
{
cout<<"请输入一串单字符数据,以*结束!"<<endl;
char ch;
//link *head;
link *r,*p,*q,*l;
l=(link *)malloc(sizeof(link));
l->next=NULL;
r=l;
ch=getchar();
// getchar();
while(ch!='*')
{
p=(link *)malloc(sizeof(link));
p->data=ch;p->next=NULL;
r->next=p;r=r->next;
ch=getchar();
// getchar();
}
//l=head;
q=print(l);
//return 0;
}
break;

case 3:
{
string s,p;
int pos,start_pos;
cout<<"输入主串:"<<endl;
cin>>s;
cout<<"输入子串"<<endl;
cin>>p;
cout<<"输入从主串开始匹配的位置:"<<endl;
cin>>start_pos;
pos=Index_KMP(s,p,start_pos);
if(!pos) cout<<"There's no substring("<<p<<")in mainstring("<<s<<")"<<endl;
else cout<<"The postion of substring("<<p<<")in mainstring("<<s<<")is "<<pos<<endl;
//system("pause");
//return 0;
}
break;
default :break;
}
}
cout<<"Continue(Y/N)?"<<endl;
cin>>Continue;

return 0;
}

B. 数据结构算法演示系统译成英文

Data Structure and Algorithm Demo System

or

Data Structure and Algorithm Demonstrate System (in full, but fussy)

C. 计算机图形学算法演示系统的设计的专业实习报告 要求用C++谁能给个成型的 急啊!!!

这个你找一下源码下载的网站,里面好像有

D. 数据结构排序算法演示系统(C版的)

你怎么不把自己捅死,还题目14,你叫别人帮你做作业啊!

E. 数据结构与算法演示系统完整简单的c++源代码,包哈内容有:线性表、二叉树、图、排序,急用!谢谢!

我有表和二叉树的,图和排序没有!那玩意不能简单的,一个就得100多行!而且只是。h文件。先给你2个吧!
#ifndef sqlIST_H
#define SQLIST_H
using namespace std;
template<class elemtype>
class sqlist
{
public:
sqlist(){head=NULL; n=0;}
virtual ~sqlist(){head=NULL;}
bool insert(const elemtype& ,int);
elemtype find(int );
void clear();
int length()const {return n;}
bool Delete(int );
protected:
int n;
struct node{
node *next;
elemtype data;
};
node *head;
};
template<class elemtype>
void sqlist<elemtype>::clear()
{
node *p,*q;
int i=1;
p=head;
while(i!=n)
{
q=p;
delete q;
p=p->next;
i++;
}
}
template<class elemtype>
bool sqlist<elemtype>::insert(const elemtype &e,int i)
{
node *p,*q;
int j=1;
if(head==NULL)
head=new node;
p=head;
if(i==1&&i>n)//表头赋值
{head->data=e;
n++;
return true;}
else if(i==1&&i<=n)//表头插入
{
head=new node;
head->data=e;
head->next=p;
n++;
return true;
}
else if(i<=n) //表中插入
{
q=new node;
q->data=e;
while(j<i-1){
p=p->next;
j++;
}
q->next=p->next;
p->next=q;
n++;
return true;}
else if(i==n+1&&i!=1)//表尾插入
{
q=new node;
q->data=e;
while (j<n)
{
p=p->next;
j++;
}
p->next=q;
q->next=NULL;
n++;
return true;}
else
return false;
}
template<class elemtype>
elemtype sqlist<elemtype>::find(int i)
{
int j=1;
node *p;
p=head;
while(j<i){
p=p->next;
j++;
}
return p->data;
}
template<class elemtype>
bool sqlist<elemtype>::Delete(int i)
{
int j=1;
node *p,*q;
p=head;
if(i!=1)//表中及表尾删除
{
while(j<i)
{
q=p;
p=p->next;
j++;
}
q->next=p->next;
delete p;
n--;
return true;}
else//表头删除
head=p->next;
delete p;
n--;
return true;
}
#endif // SQLIST_H
#ifndef binarytree_H
#define binarytree_H
#include"stack.h"
#include"queue.h"
using namespace std;
template<class elemtype>
class binarytree{
public:
binarytree(){root=NULL;}
~binarytree(){}
int height(){return height(root);}
int size(){return size(root);}
void createtree(elemtype flag);
void preorder() const ;
void midorder() const ;
void postorder() const ;
bool isempty(){return root==NULL;}
void clear(){if (root!=NULL) clear(root);}
void delleft(){ clear(root->left);}
int height()const{return height(root );}
void delright(){return clear(root->right);}
private:
struct node{
node *left,*right;
elemtype data;
node():left(NULL),right(NULL){}
node(elemtype it,node*l=NULL,node*r=NULL):data(it),left(l),right(r){}
};
node *root;
struct stnode{
node *t;
int step;
stnode(node *tc=NULL):t(tc),step(0){}
};
void clear(node *);
int size(node* );
int height(node*);
};
template<class elemtype>
void binarytree<elemtype>:: clear(node *t)
{
queue<node> la;
node *tem,*q,*p;
la.append(t);
while(!la.empty()){
tem=la.putelem();
if(tem->left!=NULL)
{ p=t->left;
la.append(p);}
if(tem->right!=NULL)
{ q=tem->right;
la.append(q);}
delete tem;
}
}
template<class elemtype>
void binarytree<elemtype>::createtree(elemtype flag)
{
queue<node*> la;
node *tem;
elemtype x,ldata,rdata;
cout<<"根节点:";
cin>>x;
root=new node(x);
la.append(root);
while(!la.isempty()){
tem=la.putelem();
cout<<"输入"<<tem->data<<"的两节点值:";
cin>>ldata>>rdata;
if(ldata!=flag) la.append(tem->left=new node(ldata));
if(rdata!=flag) la.append(tem->right=new node(rdata));
}
}
template<class elemtype>
void binarytree<elemtype>::preorder( )const
{
stack<node*> la;
node *tem;
cout<<"前序遍历为:";
la.push(root);
while(!la.empty()){
tem=la.pop();
cout<<tem->data<<" ";
if(tem->right!=NULL)
la.push(tem->right);
if(tem->left!=NULL)
la.push(tem->left);
}
}
template<class elemtype>
void binarytree<elemtype>::midorder() const
{
stack<stnode> la;
stnode tem(root);
cout<<"中序遍历:";
la.push(tem);
while(!la.empty()){
tem=la.pop();
if(++tem.step==2){
cout<<tem.t->data<<" ";
if(tem.t->right!=NULL)
la.push(stnode(tem.t->right));}
else{
la.push(tem);
if(tem.t->left!=NULL)
la.push(stnode(tem.t->left));
}
}
}
template<class elemtype>
void binarytree<elemtype>::postorder() const
{
stack<stnode> la;
stnode tem(root);
cout<<"后序遍历:";
la.push(tem);
while(!la.empty()){
tem=la.pop();
if(++tem.step==3)
{cout<<tem.t->data<<" ";continue;}
la.push(tem);
if(tem.step==1)
{
if(tem.t->left!=NULL)
la.push(stnode(tem.t->left));
}
else{
if(tem.t->right!=NULL)
la.push(stnode(tem.t->right));
}
}
}
template<class elemtype>
int binarytree<elemtype>::size(node *t)
{
queue<node*> la;
node *tem;
int a=0;
la.append(t);
while(!la.isempty()){
tem=la.putelem();
a++;
if(tem->left!=NULL)
la.append(tem->left);
if(tem->right!=NULL)
la.append(tem->right);
}
return a;
}
template<class elemtype>
int binarytree<elemtype>::height(node* t)const
{
queue<node*> la;
atack<node*> lb;
node *tmp;
la.append(t);
while(!la.isempty())
{
tmp=la.putelem();
if(tmp->left)
}
/*if(t==NULL) return 0;
else
{
int l=height(t->left),r=height(t->right);
return 1+((l>r)?l:r);
}*/
}

你还不如用stl!而且你要这玩意干什么?c++书里都有的,实在不行自己抄书不也行吗?c++的表分单链表,循环单链表,循环双链表(我给的只是单链表)。二叉树我自己用的非递归实现,除了求高度。但要用到栈和队列,你自己写吧,太多了!发着麻烦。

F. 如何利用matlab gui制作典型算法的演示系统

步骤/方法 1、新建GUI,保存,并按图示部署各控件(edit text,static texe,listbox,axes),按图修改各String 2、右击“曲线绘图”--View Callbacks--Callback,输入以下程序 3、右击“关闭”--View Callbacks--Callback,输入以下程序 4、右击“listbox控件”--View Callbacks--Callback,输入以下程序 5、运行四大环节,如下(依次为比例环节、惯性环节、比例微分环节、比例积分环节绘图) 6、自行输入函数程序,绘制任意图像,以y=sin(x)为例,点击“曲线绘制”

G. java算法演示系统

//哈哈,我做了一种排序的GUI演示
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class SortX extends JFrame{
private JLabel[]n;
private JButton start;
private JTextField in;
public SortX(){
this.getContentPane().setLayout(null);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setSize(488,200);
this.setLocationRelativeTo(null);
this.setResizable(false);
this.setAlwaysOnTop(true);
start = new JButton("start sort");
JLabel l = new JLabel("输入10组内数字:");
l.setBounds(10,18,120,20);
add(l);
in=new JTextField("10,212,7,456,33,2,55,6,50,97");
in.setBounds(118,18,256,20);
add(in);
start.setBounds(380,18,88,20);
add(start);
start.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent e){sort();}});
n=new JLabel[10];
for(int i=0; i<n.length; i++){
n[i]=new JLabel();
n[i].setFont(new Font("",Font.BOLD,14));
n[i].setForeground(Color.gray);
n[i].setHorizontalAlignment(JLabel.CENTER);
add(n[i]);
}
}
private void sort(){
setTitle("排序演示");
try{
String src = in.getText();
src=src.replaceAll("[^0-9,]","");
String[] sp = src.split(",");
final int[] v = new int[sp.length];
int left=0,w=40,offx=0,offy=95;
for(int i=0; i<n.length;i++)n[i].setText(null);
for(int i=0; i<sp.length; i++){
n[i].setText(sp[i]);
v[i] = Integer.valueOf(sp[i]);
n[i].setSize(w,20);
n[i].setLocation((left+=w)+offx,offy);
}
new Thread(){
public void run(){
start.setEnabled(false);
s(500);
try{
for(int i=0; i<n.length-1; i++){
if(v[i]>v[i+1]){
JLabel l=n[i];
n[i]=n[i+1];
n[i+1]=l;
n[i].setForeground(Color.blue);
for(int k=0; k<7; k++){
n[i].setVisible(k%2==0);
s(123);
}
swap(n[i],n[i+1]);
n[i].setForeground(Color.gray);
v[i]+=v[i+1];
v[i+1]=v[i]-v[i+1];
v[i]-=v[i+1];
i-=i==0?1:2;
}
}
}catch(Exception e){}
start.setEnabled(true);
}

private void swap(JLabel a, JLabel b) {
JLabel t = a;
a=b;
b=t;
Point pa=a.getLocation();
Point pb=b.getLocation();
int x1,x2,y1,y2;
x1=pa.x;
x2=pb.x;
y1=pa.y;
y2=pb.y;
int delay=10;
while(x1<(x1+x2)/2){
a.setLocation(++x1,y1++);
b.setLocation(--x2,y2--);
s(delay);
}
while(x1<pb.x){
a.setLocation(++x1,y1--);
b.setLocation(--x2,y2++);
s(delay);
}
a.setLocation(pb);
b.setLocation(pa);
}

private void s(int i) {
try {
sleep(i);
} catch (Exception e) {}
}
}.start();
}catch(Exception e){e.printStackTrace();setTitle("请检查输入的数据,只能输入10组哦");}
}
public static void main(String[] args) {
new SortX().setVisible(true);
}
}

H. 各种排序算法演示系统的vb程序 怎么写代码

可以搜索一下这个视频: ”排序 算法 舞蹈“

I. 我的毕设是遗传算法演示系统,可是怎么演示呢

你可以用遗传算法解决一个优化问题,比如TSP,然后做一个系统将算法搜索过程以及得到的最优解实时展示出来。

J. Web-based Java算法演示系统

表达式求值:简单点可以用开源包(eval)解决或其它解释性脚本,也可以自己实现后缀式求解
迷宫生成算法:网上可认搜得到
迷宫路径算法:可以用回溯法

希望对你有帮助

热点内容
大型php网站架构 发布:2024-09-28 12:56:59 浏览:392
编程里数字 发布:2024-09-28 12:26:52 浏览:559
java做数据库 发布:2024-09-28 12:02:37 浏览:873
ssid信息如何配置 发布:2024-09-28 11:15:10 浏览:816
下载为什么要锁屏密码 发布:2024-09-28 11:10:59 浏览:694
图像双线性插值算法 发布:2024-09-28 11:06:31 浏览:873
sql怎么执行存储过程 发布:2024-09-28 10:44:32 浏览:48
ftp服务器并发数量 发布:2024-09-28 10:19:02 浏览:545
只编译一个c文件 发布:2024-09-28 09:54:39 浏览:240
指纹密码怎么破 发布:2024-09-28 09:45:11 浏览:663