数据结构6-11
2006-06-11 12:43
113 查看
6
#include <stdio.h>
#include <string.h>
#define maxsize 100
int C[maxsize];
char A[maxsize];
void frequency()
{
char s[maxsize];
int size,n=0,same=0;
scanf("%s",&s);
size=strlen(s);
for(int j=0,k=j;j<size;j++,k++)
{
for(int p=0;p<k;p++)
{
if(s[j]==s[p])
{
same=1;
break;
// C[p]=+1;
}
else
same=0;
}
if(same==0)
{
A
=s[j];
n++;
}
}
for(int h=0;h<strlen(A);h++)
{
C[h]=0;
for(int m=0;m<strlen(s);m++)
{
if(A[h]==s[m])
C[h]++;
}
}
}
main()
{
frequency();
int len=strlen(A) ;
// printf("%d ",len);
for(int i=0;i<len;i++)
{
printf("%c %d/n",A[i],C[i]);
}
printf("Different number is:%d ",len);
}
7
#include <stdio.h>
#include < malloc.h>
typedef float DataType;
typedef struct node{
DataType data;
struct node *next;
}ListNode;
typedef ListNode *LinkList;
void delBet(DataType min,DataType max,LinkList h)
{
ListNode *p,*b;
p=h;
while(p->next!=NULL)
{
if(p->next->data>min && p->next->data<max)
{
b=p->next;
p->next=b->next;
free(b);
}
else
{
p=p->next;
}
}
}
main()
{
DataType x[10]={1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0,10.0};
LinkList head=(LinkList)malloc(sizeof(ListNode));
ListNode *s,*r,*t;
r=head;
printf("The inital data are:");
for(int i=0;i<10;i++)
{
s=(ListNode *)malloc(sizeof(ListNode));
s->data=x[i];
printf("%f ",s->data) ;
r->next=s;
r=s;
}
r->next=NULL;
delBet(0.0,9.0,head);
printf("/nThe result are:");
t=head->next;
while(t!=NULL)
{
printf("%f ",t->data);
t=t->next;
}
}
8
#include <stdio.h>
int pal(char A[],int s,int e)
{
int i=(e-s)/2;
for(int j=0;j<i;j++,s++,e--)
{
if(A[s-1]!=A[e-1])
return 0;
}
return 1;
}
main()
{
char Ch[500];
scanf("%s",Ch);
printf("%d",pal(Ch,1,5));
}
9
#include <stdio.h>
#include <malloc.h>
typedef struct BinTreeNode{
char data;
BinTreeNode *lChild,*rChild;
}BinTreeNode,*BinTree;
//typedef BinTreeNode* BinTree;
int BTreeHeight(BinTree BT)
{
int dep1,dep2,max;
if(BT==NULL)
return 0;
else
{
dep1=BTreeHeight(BT->lChild);
dep2=BTreeHeight(BT->rChild);
if(dep1>dep2)
max=dep1;
else
max=dep2;
return max+1;
}
}
int CreateBTree(BinTree *b)
{
char ch;
ch=getchar();
if(ch=='.')
{
*b=NULL;
}
else
{
(*b)=(BinTree)malloc(sizeof(BinTreeNode));
(*b)->data=ch;
CreateBTree(&((*b)->lChild));
CreateBTree(&((*b)->rChild));
}
}
main()
{
int high;
BinTree p=NULL;
CreateBTree(&p);
high=BTreeHeight(p);
printf("The high is:%d",high);
}
10
#include <stdio.h>
int BinSearch(long R[],int n,long k)
{
int low=0,high=n-1,mid;
while(low<=high)
{
mid=(low+high)/2;
if(k==R[mid])
return mid;
else if(k<R[mid])
high=mid-1;
else
low=mid+1;
}
return -1;
}
main()
{
int temp;
long s[10]={1.2,3.4,5.6,6.8,7.9,8.9,9.0,11.0,12.9,14.0};
temp=BinSearch(s,10,9.0);
printf("%d",temp);
}
11
#include <stdio.h>
#include <string.h>
int static s1[10]={2,3,5,4,6,7,9,8,10,1};
int s2[10];
void countSort()
{
int temp,k;
for(int i=0;i<10;i++)
{
temp=s1[i];
k=0;
for(int j=0;j<10;j++)
{
if(temp>s1[j])
k++;
}
s2[k]=temp;
}
}
main()
{
printf("The unsorted numbers are:");
for(int t=0;t<10;t++)
{
printf("%d ",s1[t]);
}
countSort();
printf("/nThe sorted numbers are:");
for(int p=0;p<10;p++)
{
printf("%d ",s2[p]);
}
}
#include <stdio.h>
#include <string.h>
#define maxsize 100
int C[maxsize];
char A[maxsize];
void frequency()
{
char s[maxsize];
int size,n=0,same=0;
scanf("%s",&s);
size=strlen(s);
for(int j=0,k=j;j<size;j++,k++)
{
for(int p=0;p<k;p++)
{
if(s[j]==s[p])
{
same=1;
break;
// C[p]=+1;
}
else
same=0;
}
if(same==0)
{
A
=s[j];
n++;
}
}
for(int h=0;h<strlen(A);h++)
{
C[h]=0;
for(int m=0;m<strlen(s);m++)
{
if(A[h]==s[m])
C[h]++;
}
}
}
main()
{
frequency();
int len=strlen(A) ;
// printf("%d ",len);
for(int i=0;i<len;i++)
{
printf("%c %d/n",A[i],C[i]);
}
printf("Different number is:%d ",len);
}
7
#include <stdio.h>
#include < malloc.h>
typedef float DataType;
typedef struct node{
DataType data;
struct node *next;
}ListNode;
typedef ListNode *LinkList;
void delBet(DataType min,DataType max,LinkList h)
{
ListNode *p,*b;
p=h;
while(p->next!=NULL)
{
if(p->next->data>min && p->next->data<max)
{
b=p->next;
p->next=b->next;
free(b);
}
else
{
p=p->next;
}
}
}
main()
{
DataType x[10]={1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0,10.0};
LinkList head=(LinkList)malloc(sizeof(ListNode));
ListNode *s,*r,*t;
r=head;
printf("The inital data are:");
for(int i=0;i<10;i++)
{
s=(ListNode *)malloc(sizeof(ListNode));
s->data=x[i];
printf("%f ",s->data) ;
r->next=s;
r=s;
}
r->next=NULL;
delBet(0.0,9.0,head);
printf("/nThe result are:");
t=head->next;
while(t!=NULL)
{
printf("%f ",t->data);
t=t->next;
}
}
8
#include <stdio.h>
int pal(char A[],int s,int e)
{
int i=(e-s)/2;
for(int j=0;j<i;j++,s++,e--)
{
if(A[s-1]!=A[e-1])
return 0;
}
return 1;
}
main()
{
char Ch[500];
scanf("%s",Ch);
printf("%d",pal(Ch,1,5));
}
9
#include <stdio.h>
#include <malloc.h>
typedef struct BinTreeNode{
char data;
BinTreeNode *lChild,*rChild;
}BinTreeNode,*BinTree;
//typedef BinTreeNode* BinTree;
int BTreeHeight(BinTree BT)
{
int dep1,dep2,max;
if(BT==NULL)
return 0;
else
{
dep1=BTreeHeight(BT->lChild);
dep2=BTreeHeight(BT->rChild);
if(dep1>dep2)
max=dep1;
else
max=dep2;
return max+1;
}
}
int CreateBTree(BinTree *b)
{
char ch;
ch=getchar();
if(ch=='.')
{
*b=NULL;
}
else
{
(*b)=(BinTree)malloc(sizeof(BinTreeNode));
(*b)->data=ch;
CreateBTree(&((*b)->lChild));
CreateBTree(&((*b)->rChild));
}
}
main()
{
int high;
BinTree p=NULL;
CreateBTree(&p);
high=BTreeHeight(p);
printf("The high is:%d",high);
}
10
#include <stdio.h>
int BinSearch(long R[],int n,long k)
{
int low=0,high=n-1,mid;
while(low<=high)
{
mid=(low+high)/2;
if(k==R[mid])
return mid;
else if(k<R[mid])
high=mid-1;
else
low=mid+1;
}
return -1;
}
main()
{
int temp;
long s[10]={1.2,3.4,5.6,6.8,7.9,8.9,9.0,11.0,12.9,14.0};
temp=BinSearch(s,10,9.0);
printf("%d",temp);
}
11
#include <stdio.h>
#include <string.h>
int static s1[10]={2,3,5,4,6,7,9,8,10,1};
int s2[10];
void countSort()
{
int temp,k;
for(int i=0;i<10;i++)
{
temp=s1[i];
k=0;
for(int j=0;j<10;j++)
{
if(temp>s1[j])
k++;
}
s2[k]=temp;
}
}
main()
{
printf("The unsorted numbers are:");
for(int t=0;t<10;t++)
{
printf("%d ",s1[t]);
}
countSort();
printf("/nThe sorted numbers are:");
for(int p=0;p<10;p++)
{
printf("%d ",s2[p]);
}
}
相关文章推荐
- 数据结构基础(11) --循环链表的设计与实现
- 数据结构基础(11) --循环链表的设计与实现
- 【算法学习笔记】11.数据结构基础 二叉树初步练习4
- 【数据结构之排序11】各种内部排序方法的比较和选择
- 实战数据结构(11)_二叉树的遍历
- 看数据结构写代码(11)栈的应用(二) 括号匹配的检查
- 数据结构(11)线性表之一元多项式表示及相加
- 数据结构基础(11) --循环链表的设计与实现
- 【算法学习笔记】11.数据结构基础 二叉树初步练习4
- 数据结构——树(11)——AVL树的实现(1)
- 数据结构(11)--串的模式匹配算法之BF、KMP算法
- 数据结构——双向循环链表——2016_11_14
- 11、数据结构笔记之十一栈的应用之表达式求值实现
- 剑指offer--数据结构之二叉树(1、4、6、11、12、27、48、50、60)
- 11.数据结构(4)
- 数据结构之队列11循环队列定义及实现
- PTA 数据结构与算法题目集(中文)5-11 关键活动 (30分)
- 数据结构基础(11)------------输出字符串的所有组合( Permutation)--腾讯笔试附加题
- 小技巧(11)-Jquery递归获取XML数据生成ul-li结构
- 数据结构——栈——2016_11_21