| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 15815 人关注过本帖, 6 人收藏
标题:本学期我学习数据结构的一些练习,现在发上来,希望能给初学者带来帮助
只看楼主 加入收藏
gevin
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2005-12-17
收藏
得分:0 

对于我很有用,谢谢!请问有没有Huffman编码与译码的C程序吗?不胜感激!

2005-12-17 20:52
forgetful
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2005-12-23
收藏
得分:0 

(1) 建立一棵二叉排序树,并在所建立的二叉叉排序树中可插入某一结点及删除任一结点,要求插入和删除后不破坏原二叉排序树的结构。

(2) 画出你所建的这棵二叉排序树,并能动态反映你所插入结点、删除结点及删除时结点继承的过程(具有可视化、彩色、美观的效果)。

(3) 能查找任一结点的左、右孩子

(4) 能查找任一结点的所有兄弟

(5) 能查找任一结点的父亲

提示:一定设计好界面,界面要求设计漂亮,界面占相当比例。
用C语言
兄弟,会的话,就帮帮忙,急用.谢谢!!

2005-12-23 18:15
doctor1
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2005-12-21
收藏
得分:0 

兄弟, 好东东呀

2005-12-24 14:56
langzi1985
Rank: 1
等 级:新手上路
帖 子:10
专家分:0
注 册:2005-12-21
收藏
得分:0 
[讨论]

有就发上来啊,供大家学习参考嘛


为了网络而活。
2005-12-25 13:10
wuduguer
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2005-12-29
收藏
得分:0 

我想要关于2-3树的程序
帮忙呀

2005-12-29 08:47
muyilion
Rank: 1
等 级:新手上路
帖 子:13
专家分:0
注 册:2005-12-26
收藏
得分:0 
收下了,3x
2005-12-29 11:38
樱桃小新
Rank: 1
等 级:新手上路
帖 子:29
专家分:0
注 册:2005-10-26
收藏
得分:0 

不好意思,各位,上次发完后来就一直没上网,就回学校了,这新年了才回来,我把剩下的发给大家伙

2006-01-03 15:01
樱桃小新
Rank: 1
等 级:新手上路
帖 子:29
专家分:0
注 册:2005-10-26
收藏
得分:0 

霍夫曼编码的
#include <malloc.h>
#include <stdio.h>
#include <string.h>
#define List_Max_Size 100
#define Add_Size 10
#define Null 0


struct Huffman_Data {
char Word[2];
int Weight,LChild,RChild,Parent;
};//定义顺序表数据结构体
typedef Huffman_Data Thread_Save_Struct;

struct Thread_1 {
int Length;
int List_Size;
Thread_Save_Struct *Point;
};//定义顺序表指针结构体
typedef Thread_1 Thread;

typedef struct {
int Min_Weight,Addres;
}Min;

int Create_List( Thread &List )
{
List.Point = (Thread_Save_Struct * )malloc ( sizeof(Thread_Save_Struct) * List_Max_Size);
if ( !List.Point ) return (0);
List.List_Size = List_Max_Size;
List.Length = 0;
return (1);
}//建立一个顺序表


int main ()
{ int Code_Amount,Weight,Value,OnOff=1;
int Create_List( Thread &List );
int Add = 0,Add_1,e=0;
Min j,i;
char Code[100],Code_Swap[100];
Thread_Save_Struct *Point_1;
Thread User;


if (Create_List(User)==1)
{
printf("\n","存储空间开辟成功");

for (Point_1 = (User.Point)+1;OnOff==1 && User.Length<User.List_Size;Point_1++)
{ printf("在此输入字符:");
scanf("%s", Point_1->Word);
printf("在此输入权值:");
scanf("%d", &(Point_1->Weight));
Point_1->Parent = Null;
Point_1->LChild = Null;
Point_1->RChild = Null;
printf("是否继续输入?是(1),否(0):");
scanf("%d",&OnOff);
User.Length++;
}//for

}//if
else printf("%s\n","存储空间开辟失败");
i.Min_Weight=0;
j.Min_Weight=0;
while (i.Min_Weight!=-1 && j.Min_Weight!=-1)
{ i.Min_Weight =-1,j.Min_Weight =-1;
Point_1 = User.Point;
for(Add=1;Add<=User.Length;Add++)
{
if ((Point_1+Add)->Parent == 0)
{
if (i.Min_Weight ==-1||j.Min_Weight ==-1)
{
if (i.Min_Weight ==-1)
{
i.Min_Weight =(Point_1+Add)->Weight;
i.Addres = Add;
}
else if (j.Min_Weight ==-1)
{
j.Min_Weight =(Point_1+Add)->Weight;
j.Addres = Add;
}
}else if((Point_1+Add)->Weight<=i.Min_Weight||(Point_1+Add)->Weight<=j.Min_Weight)
{
if (i.Min_Weight >=j.Min_Weight )
{
i.Min_Weight =(Point_1+Add)->Weight;
i.Addres = Add;
}
if (j.Min_Weight >i.Min_Weight )
{
j.Min_Weight =(Point_1+Add)->Weight;
j.Addres = Add;
}
}//else if
}//if

}//for
if (i.Min_Weight!=-1 && j.Min_Weight!=-1)
{
(Point_1+Add)->Weight = (i.Min_Weight)+(j.Min_Weight);
if ((i.Min_Weight)<=(j.Min_Weight))
{
(Point_1+Add)->LChild =i.Addres;
(Point_1+Add)->RChild =j.Addres;
}
if ((i.Min_Weight)> (j.Min_Weight))
{
(Point_1+Add)->RChild =i.Addres;
(Point_1+Add)->LChild =j.Addres;
}
(Point_1+i.Addres)->Parent = Add;
(Point_1+j.Addres)->Parent = Add;
User.Length++;
}//if

}//while
Add=1;
for (Point_1 = (User.Point+1);Add != User.Length+1 ;Point_1++)
{
printf("parent%d,",Point_1->Parent);
printf("LChild:%d,",Point_1->LChild);
printf("RChild:%d,",Point_1->RChild);
printf("字符:%s,",Point_1->Word);
printf("权值:%d\n",Point_1->Weight);
Add++;
}//for

Point_1 = User.Point;e=0;
for (Add=1;Add<=(User.Length+1+1)/2;Add++)
{
Code[e++]=(Point_1+Add)->Word[0];
for (Add_1=Add;(Point_1+Add_1)->Parent!=0;)
{
if ((Point_1+((Point_1+Add_1)->Parent))->LChild==Add_1) Code[e++]='0';
if ((Point_1+((Point_1+Add_1)->Parent))->RChild==Add_1) Code[e++]='1';
Add_1=(Point_1+Add_1)->Parent;
}
}
printf("%s,",Code);
scanf("%d", &OnOff);
return 1;
}
这个编码还缺最后一个反转编码的小函数,也就是说,正常找码需要从叶子往根找然后再把码调过来,我懒了点,后面的反转函数没写,不好意思,呵呵

2006-01-03 15:05
樱桃小新
Rank: 1
等 级:新手上路
帖 子:29
专家分:0
注 册:2005-10-26
收藏
得分:0 

这个是稀疏矩阵的三元表存储,和转置


#define ROW 4
#define COL 4
#define Max_Size 9 //非零元最大个数
#include <stdio.h>
typedef int Data;

typedef struct
{
int Row,Col;
Data e;
}Sparse;

typedef struct
{
Sparse Grid[Max_Size+1];
int Count_Row,Count_Col,None_O;
}Tg_Array;


int main()
{

Sparse Sp_Grid;
Tg_Array Grid_1,Grid_T;
int Reg[ROW][COL] = {{1,0,3,0},{2,1,5,0},{0,8,1,0},{9,0,0,1}},Out_Reg[ROW][COL],Out_Reg_T[ROW][COL];
int Count_Col,Count_Row,Count=1,Count_1=1,Count_2=1;
Grid_1.Count_Row = ROW,Grid_1.Count_Col = COL;



//打印此距阵
for (Count_Row=0;Count_Row<ROW;Count_Row++)
{ for (Count_Col=0;Count_Col<COL;Count_Col++)
{
printf("%d,",Reg[Count_Row][Count_Col]);
}
printf("\n");
}


//将稀疏距阵存入三元组中(以行为主序存)
for (Count_Row=0;Count_Row<ROW;Count_Row++)
{
for (Count_Col=0;Count_Col<COL;Count_Col++)
{

if (Reg[Count_Row][Count_Col]!=0)
{
if (Count > Max_Size )
{ printf("非零元个数超出限定最大值\n");
break;
}
Grid_1.Grid[Count].Row=Count_Row;
Grid_1.Grid[Count].Col=Count_Col;
Grid_1.Grid[Count].e=Reg[Count_Row][Count_Col];
Grid_1.None_O++;
Count++;
}
}

}

//矩阵的转置(行主序)
Count_Row = 0;
Count_Col=0;
for(Count = 1;Count<=Max_Size;Count++)
{
for(Count_1=1;Count_1<=Max_Size;Count_1++)
{
if (Grid_1.Grid[Count_1].Col==Count-1)
{
Grid_T.Grid[Count_2].Row = Grid_1.Grid[Count_1].Col;
Grid_T.Grid[Count_2].Col = Grid_1.Grid[Count_1].Row;
Grid_T.Grid[Count_2].e = Grid_1.Grid[Count_1].e;
Count_2++;
}
}
}

//根据三元组输出距阵 (行主序)
Count_Row = 0;
Count_Col=0;
Count = 1;

for (Count_Row=0;Count_Row<ROW;Count_Row++)
{
for (Count_Col=0;Count_Col<COL;Count_Col++)
{ if (Count_Row == Grid_1.Grid[Count].Row && Count_Col == Grid_1.Grid[Count].Col)
Out_Reg[Count_Row][Count_Col]= Grid_1.Grid[Count++].e;
else Out_Reg[Count_Row][Count_Col]= 0;
}
}

//根据转置三元组输出距阵 (行主序)
Count_Row = 0;
Count_Col=0;
Count = 1;

for (Count_Row=0;Count_Row<ROW;Count_Row++)
{
for (Count_Col=0;Count_Col<COL;Count_Col++)
{ if (Count_Row == Grid_T.Grid[Count].Row && Count_Col == Grid_T.Grid[Count].Col)
Out_Reg_T[Count_Row][Count_Col]= Grid_T.Grid[Count++].e;
else Out_Reg_T[Count_Row][Count_Col]= 0;
}
}


//打印输出数组
printf("输出稀疏矩阵为:\n");
for (Count_Row=0;Count_Row<ROW;Count_Row++)
{ for (Count_Col=0;Count_Col<COL;Count_Col++)
{
printf("%d,",Out_Reg[Count_Row][Count_Col]);
}
printf("\n");
}


//打印输出转置数组
printf("输出转置稀疏矩阵为:\n");
for (Count_Row=0;Count_Row<ROW;Count_Row++)
{ for (Count_Col=0;Count_Col<COL;Count_Col++)
{
printf("%d,",Out_Reg_T[Count_Row][Count_Col]);
}
printf("\n");
}


scanf("%d",&Count_Col);
return 1;
}

2006-01-03 15:06
樱桃小新
Rank: 1
等 级:新手上路
帖 子:29
专家分:0
注 册:2005-10-26
收藏
得分:0 

这个试图的邻接表存储和遍历

#include <malloc.h>
#include <string.h>
#define List_Max_Size 100
#define Add_Size 10
#define Null 0
#define Row 4
#define True 1
#define False 0
#include <stdio.h>

struct Element{
int Data,Addr,Length;
struct Element *Next,*Pre;
};//定义链式表数据结构体
typedef Element Chain_Save_Struct;
typedef Element Head_Chain;

int Create_Chain( Chain_Save_Struct &List )
{
List.Length = 0;
List.Next = Null;
List.Pre = Null;
return (1);
}//建立一个链式表

int Add_Chain ( Head_Chain &List,Chain_Save_Struct **Position)
{
Chain_Save_Struct *Position_1,*PreP;
if (List.Next==Null)
{
List.Next = (Chain_Save_Struct * )malloc ( sizeof(Chain_Save_Struct));
if (!List.Next) return(0);
List.Length=1;
(List.Next -> Next) = Null;
(List.Next ->Pre) = &List;
*Position = List.Next;
return(1);
}
else
{
Position_1 = *Position;
for (*Position = (List.Next);
*Position !=NULL; *Position=(*Position)->Next)PreP = *Position;
PreP->Next = (Chain_Save_Struct * )malloc ( sizeof(Chain_Save_Struct));
if (!List.Next) return(0);
List.Length++;
(PreP->Next->Next) = Null;
(PreP->Next->Pre)= PreP;
*Position = Position_1;
return(1);
}
}//为链表添加一个元素;

int Del_Chain (Chain_Save_Struct &List,Chain_Save_Struct **Position)
{ int a,b,c;
Chain_Save_Struct *PreP,*NPosition;
PreP = Null;
if (List.Next==Null||(*Position)->Pre==Null)
{
return 0;
}//if 链表为空表时
for (NPosition=&List;
NPosition != *Position; NPosition = NPosition->Next)PreP = NPosition;//找到当前删除节点的前驱
NPosition = (*Position)->Next;//当前节点的后继
free(*Position);
--List.Length;
//分为当前节点无后继,当前节点有后继两种情况
if (NPosition == Null)
{ *Position =PreP;
printf("无后继");

scanf("%d",&a);
(*Position)->Next = Null ;
return 1;// 当前节点无后继节点
}
else if (NPosition != Null)
{ printf("有后继");

scanf("%d",&a);
*Position = PreP;
PreP->Next = NPosition;
NPosition->Pre = PreP;
return 1;

}//当前节点有后继节点
}

int Chain_Next (Chain_Save_Struct **Position)
{ if (*Position==Null)return 0;
if ((*Position)->Next == Null) return 0;
*Position=((*Position)->Next);
return 1;
}//下移一个位置

int Chain_Pre (Chain_Save_Struct **Position)
{
if (*Position==Null)return 0;
if ((*Position)->Pre == Null) return 0 ;
*Position=((*Position)->Pre);
return 1;
}//上移一个位置

int Opera(Chain_Save_Struct Adj[Row],int Addr)
{
Adj[Addr].Data = False;
printf("Add=%d,",Addr);

return 1;
}//操作节点


int Deep_Order(Chain_Save_Struct Adj[Row],int Addr)
{
// Opera(Chain_Save_Struct Adj[Row],int Addr);
Element *Point;
Opera(Adj,Addr);
printf(",%d",Adj[Addr].Next);

for(Point = Adj[Addr].Next;Point.Next!=Null && Adj[Point->Addr].Data==False;Point=Point->Next);
Point =Point->Next
if (Point==Null)
{

for(Addr = 0;Addr<=Row-1;Addr++)
{
if (Adj[Addr].Data==True)break;
else if (Addr == Row-1)return 1;
}
}
Deep_Order(Adj,Point->Addr);






return 1;
}//图的邻接表的深度遍历



int main()
{ int Tragle[Row][Row] = {{0,0,0,0},{1,0,1,1},{0,0,0,1},{1,0,0,0}};
Chain_Save_Struct Adj_List[Row],*Point;
int Deep_Order(Chain_Save_Struct Adj[Row],int Addr);
int Addr;
int i,j,Col;
for (i=0;i<=(Row-1);i++)
{
Create_Chain(Adj_List[i]);
Adj_List[i].Data = True;
Point=&(Adj_List[i]);
for (j=0;j<=(Row-1);j++)
{
if (Tragle[i][j]==1)
{
Add_Chain(Adj_List[i],&Point);
if (Point->Next!=Null)Point=Point->Next;
Point->Addr =j;
}
}
}//根据给定的矩阵求图的逆邻接表

for (i=0;i<=(Row-1);i++)
{
printf("是否被访问过:%d,",Adj_List[i].Data);
printf("节点名=%d",i);
for (Point=Adj_List[i].Next;Point!=Null;Point=Point->Next)
{
printf("->%d",Point->Addr);
}
printf("\n");
}

//逆邻接表在此位置
//图的深度优先遍历
Addr =0;
Deep_Order(Adj_List, Addr);
//图的广度优先遍历

scanf("%d",Col);
return 1;
}

2006-01-03 15:08
快速回复:本学期我学习数据结构的一些练习,现在发上来,希望能给初学者带来帮助 ...
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.065702 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved