标题:求大神将完成这段代码
只看楼主
哎哟
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2016-5-23
 问题点数:0 回复次数:1 
求大神将完成这段代码
//Dev-C++ generate, C++ relative
#include <cstdlib>
#include <iostream>
using namespace std;

//Include necessary C libs
#include<stdio.h>
#include <stdarg.h>
#include<math.h>

//Declare function
int Detect_Tags(struct bit_data *transmit_data, struct bit_data *tag_result);
void Set_Bit_Data(struct bit_data *value, int count, ...);
void Merge_Bit_Data(struct bit_data *dest_value, struct bit_data *value1, struct bit_data value2);
void Print_Bit_Data(struct bit_data *transmit_data);
void QTA_Detect_Tags(struct bit_data *transmit_data);//广度有限遍历
void Set_Node(struct node *tree_node, struct bit_data node_data);
void Print_Node(struct node *tree_node);
void Initial_Binary_Tree(struct node *node_ptr, int level, struct bit_data node_value);
void DFS_Detect_Tags(struct node *node_ptr, struct bit_data transmit_data);//深度优先遍历

//Define constant
#define TAG_COUNT 4
#define TAG_BIT 4

//Declare struct
struct bit_data
{
    int bit_count;
    int bit_content[TAG_BIT];

};

struct node
{

    struct bit_data value;
    struct node *left_child;
    struct node *right_child;

};

//Global variables
int tags[TAG_COUNT][TAG_BIT]={
{
0, 0, 0, 1
}, {
0, 1, 0, 0
}, {
0, 1, 0, 1
}, {
1, 0, 0, 0
}, {
1, 0, 1, 0
}
};
int search_counter=0;

//Program Start
int main(int argc, char *argv[])
{

int i, j;
int method;

printf("=====RFID=====\n\n");
printf("There are 2 searching method:\n");
printf("1. QTA\n");
printf("2. DFS\n\n");
printf("Please choose searching method: ");
scanf("%d", &method);
printf("\n\n");

if(method==1)
{

//广度优先遍历
struct bit_data transmit_data;
transmit_data.bit_count=0;

//Hint
printf("=====QTA detect tags=====\n\n");
printf("#Test Case Information:\n");
printf("Tag Count: %d\n", TAG_COUNT);
printf("Tag Bits:? %d Bits\n", TAG_BIT);
printf("Tag List:\n");
for(i=0; i<TAG_COUNT; i++)
{

for(j=0; j<TAG_BIT; j++)
{

printf("%d", tags[i][j]);

}
printf("\n");

}
printf("\n\n");

//Use QTA to detect tags
printf("#QTA detect tags...\n\n");
QTA_Detect_Tags(&transmit_data);
printf("#QTA finish!!!\n\n");

}
else if(method==2)
{

//深度优先遍历
struct node *root_ptr;
struct bit_data root_value;

Set_Bit_Data(&root_value, 5, 1, 2, 3, 4, 9); //root data, data count = 0
printf("\n~~~\n");
Print_Bit_Data(&root_value);
printf("%d", root_value.bit_count);
printf("\n~~~\n");
Set_Bit_Data(&root_value, 0); //设置根节点数据为0
printf("\n~~~\n");
Print_Bit_Data(&root_value);
printf("%d", root_value.bit_count);
printf("\n~~~\n");

//Hint
printf("=====DFS Detect tags=====\n\n");

//初始化二叉树
printf("#Initial binary tree...\n\n");
printf("%d", root_ptr->value.bit_count);
Initial_Binary_Tree(root_ptr, 0, root_value);
printf("#Initial success\n\n");

printf("#DFS detect tags...\n\n");
printf("%d", root_ptr->value.bit_count);
printf("%d", root_value.bit_count);
DFS_Detect_Tags(root_ptr, root_value);
printf("#DFS finish!!!\n\n");


}

system("PAUSE");
return 0;

}

//Detect Tags休眠标签
int Detect_Tags(struct bit_data *transmit_data, struct bit_data *tag_result)
{

int i, j;
int fit_flag;
int fit_count=0;
int fit_tag_index;

for(i=0; i<TAG_COUNT; i++)
{

fit_flag=1;
for(j=0; j<transmit_data->bit_count; j++)
{

if(transmit_data->bit_content[j] != tags[i][j])
{

fit_flag=0;
break;

}

}

if(fit_flag==1)
{

fit_tag_index=i;
fit_count++;

}

}

if(fit_count == 1)
{

tag_result->bit_count=TAG_BIT;
for(i=0; i<TAG_BIT; i++)
{

tag_result->bit_content[i]=tags[fit_tag_index][i];

}

}

return fit_count;

}

//设置位值
void Set_Bit_Data(struct bit_data *value, int count, ...)
{

int i;

va_list ap;

value->bit_count=count;

//test
//printf("!!!IN SetBitData, count=%d\n",value->bit_count);

va_start(ap, count);
for(i=0; i<count; i++)
{

value->bit_content[i]=va_arg(ap, int);
//test
//printf("!!!IN SetBitData, i=%d, content=%d\n", i, value->bit_content[i]);

}
va_end(ap);

}

//Merge Bit Data
void Merge_Bit_Data(struct bit_data *dest_value, struct bit_data value1, struct bit_data value2)
{

int i;

printf("\n***00\n");
printf("%d", dest_value->bit_count);
printf("%d", value1.bit_count);
printf("%d", value2.bit_count);
Print_Bit_Data(dest_value);
Print_Bit_Data(&value1);
Print_Bit_Data(&value2);


dest_value->bit_count=value1.bit_count+value2.bit_count;

for(i=0; i<value1.bit_count; i++)
{

dest_value->bit_content[i]=value1.bit_content[i];


for(i=0; i<value2.bit_count; i++)
{

dest_value->bit_content[i+value1.bit_count]=value2.bit_content[i];

};
printf("\n***01\n");
printf("%d", dest_value->bit_count);
printf("%d", value1.bit_count);
printf("%d", value2.bit_count);
Print_Bit_Data(&value1);
Print_Bit_Data(&value2);
Print_Bit_Data(dest_value);

}

//打印序列号
void Print_Bit_Data(struct bit_data *transmit_data)
{

int i;
for(i=0; i<transmit_data->bit_count; i++)
{

printf("%d", transmit_data->bit_content[i]);

}

}
//QTA(Query Tree Algorithm) detect tags
void QTA_Detect_Tags(struct bit_data *transmit_data)
{

int level;
level=transmit_data->bit_count;

printf("#Reader action counter, No. %d\n%s", search_counter++, (level==0)?"\n":"");

if(level > 0)//Not root, reader transmit data
{

int i;
int detect_result;
struct bit_data tag;

printf("@Reader send ");
Print_Bit_Data(transmit_data);
printf("\n");

detect_result=Detect_Tags(transmit_data, &tag);

if(detect_result==0) //没有标签应答
{

printf("$No tag response\n\n");
return;

}
else if(detect_result==1)//只有一个标签应答
{

printf("$Only one tag response, the tag ID is ");
Print_Bit_Data(&tag);
printf("\n\n");
return;

}
else //多个标签
{

printf("$More than one tag response\n\n");

}

}

//Because more than one tag response, so continue transmit next bit

//Search 0 sub tree
transmit_data->bit_count=level+1;
transmit_data->bit_content[level]=0;
QTA_Detect_Tags(transmit_data);

//Search 1 sub tree
transmit_data->bit_count=level+1;
transmit_data->bit_content[level]=1;
QTA_Detect_Tags(transmit_data);

}

//Set Node
void Set_Node(struct node *tree_node, struct bit_data node_data)
{

int i;

tree_node->value.bit_count=node_data.bit_count;
tree_node->left_child=NULL;
tree_node->right_child=NULL;

for(i=0; i<node_data.bit_count; i++)
{

tree_node->value.bit_content[i]=node_data.bit_content[i];

}

}

//Print Node
void Print_Node(struct node *tree_node)
{

Print_Bit_Data(&(tree_node->value));

}

//Initial Binary Tree, create by DFS method, for function of DFS_Detect_Tags() useing
void Initial_Binary_Tree(struct node *node_ptr, int level, struct bit_data node_value)
{

node_ptr=(struct node *)malloc(sizeof(struct node));

//test
printf("\nIn initial\n");
if(node_ptr==NULL)
printf("malloc fail ");
else
printf("malloc success ");

Set_Node(node_ptr, node_value);


printf("node_ptr->value.bit_count=%d\n\n", node_ptr->value.bit_count);
//Print_Bit_Data(&node_value);
//Print_Node(node_ptr);

if(level<=TAG_BIT)
{

//Set left subtree
Set_Bit_Data(&node_value, 1, 0);???????? //left node value is 0
Initial_Binary_Tree(node_ptr->left_child, level+1, node_value);

//Set right subtree
Set_Bit_Data(&node_value, 1, 1);???????? //right node value is 1
Initial_Binary_Tree(node_ptr->right_child, level+1, node_value);

}

}

搜索更多相关主题的帖子: necessary 
2016-05-26 17:26
书生牛犊
Rank: 14Rank: 14Rank: 14Rank: 14
来 自:星夜征程
等 级:贵宾
威 望:10
帖 子:1101
专家分:5265
注 册:2015-10-27
得分:0 
?想问什么?
如果是代码不能正确运行的话推荐你把帖子发到对应的C++语言板块,
数据结构是万能的,但他毕竟只是一种思想/方法,具体的实现是可以很不一样的。

φ(゜▽゜*)♪
2016-06-27 23:13



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-465277-1-1.html




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

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