I
iskeletor
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#define STUDENT_NUMBER 68
#define ARRAY_LENGTH 10
struct node{
char Name,Surname;
int data,no;
struct node *left,*right,*datA;
};
typedef struct node node;
/*prototypes*/
void buildTree();
node* createNode(char[],char[],int);
//void insert(node,int,char,char);
node *root=NULL,*nod=NULL;
long ID,order,nodeNumber,depth=0;
char name[10],familyName[10];
int main()
{
buildTree();
return 0;
}
void buildTree(){
FILE *file;
if((file=fopen("data.txt","r"))==NULL){
printf("File couldn't be opened!\n");
}else{
while(!feof(file)){
fscanf(file,"%ld%ld%s%s",&order,&ID,name,familyName);
printf("order=%ld,ID=%ld,name=%s,familyName=%s\n",order,ID,name,familyName);
root=createNode(*familyName,*name,ID);/*HERE THERE IS A
PROBLEM:COMPILER WANTS CASTING BUT HOW WILL I DO IT?*/
}
}
fclose(file);
}
node* createNode(char srnm[],char nm[],int noo){
node* newNode;
newNode=(node*)(malloc(sizeof(node)));
newNode->Surname=*(srnm);
newNode->Name=*(nm);
newNode->no=noo;
newNode->left=NULL;
newNode->right=NULL;
return newNode;
}
void add(node *nd,long id[],char namE[],char surnamE[]){
while(pow(2,depth+1)!=STUDENT_NUMBER){
depth++;
}
if(depth%3==0){
*nod->datA=namE;/*HERE SAME PROBLEM AGAIN*/
}
if(depth%3==2){
*nod->datA=id; /*HERE SAME PROBLEM AGAIN*/
}
if(depth%3==0){
*nod->datA=surnamE; /*HERE SAME PROBLEM AGAIN*/
}
if(nod.datA>nd->no){
if(nd->right==NULL){
nd->right=createNode(namE,surnamE,id);
}else{
add(nd->right,id,namE,surnamE);
}
}
else
{
if(nd->left==NULL){
nd->left=createNode(namE,surnamE,id);
}else{
add(nd->left,id,namE,surnamE);
}
}
}
#include <string.h>
#include <math.h>
#include <stdlib.h>
#define STUDENT_NUMBER 68
#define ARRAY_LENGTH 10
struct node{
char Name,Surname;
int data,no;
struct node *left,*right,*datA;
};
typedef struct node node;
/*prototypes*/
void buildTree();
node* createNode(char[],char[],int);
//void insert(node,int,char,char);
node *root=NULL,*nod=NULL;
long ID,order,nodeNumber,depth=0;
char name[10],familyName[10];
int main()
{
buildTree();
return 0;
}
void buildTree(){
FILE *file;
if((file=fopen("data.txt","r"))==NULL){
printf("File couldn't be opened!\n");
}else{
while(!feof(file)){
fscanf(file,"%ld%ld%s%s",&order,&ID,name,familyName);
printf("order=%ld,ID=%ld,name=%s,familyName=%s\n",order,ID,name,familyName);
root=createNode(*familyName,*name,ID);/*HERE THERE IS A
PROBLEM:COMPILER WANTS CASTING BUT HOW WILL I DO IT?*/
}
}
fclose(file);
}
node* createNode(char srnm[],char nm[],int noo){
node* newNode;
newNode=(node*)(malloc(sizeof(node)));
newNode->Surname=*(srnm);
newNode->Name=*(nm);
newNode->no=noo;
newNode->left=NULL;
newNode->right=NULL;
return newNode;
}
void add(node *nd,long id[],char namE[],char surnamE[]){
while(pow(2,depth+1)!=STUDENT_NUMBER){
depth++;
}
if(depth%3==0){
*nod->datA=namE;/*HERE SAME PROBLEM AGAIN*/
}
if(depth%3==2){
*nod->datA=id; /*HERE SAME PROBLEM AGAIN*/
}
if(depth%3==0){
*nod->datA=surnamE; /*HERE SAME PROBLEM AGAIN*/
}
if(nod.datA>nd->no){
if(nd->right==NULL){
nd->right=createNode(namE,surnamE,id);
}else{
add(nd->right,id,namE,surnamE);
}
}
else
{
if(nd->left==NULL){
nd->left=createNode(namE,surnamE,id);
}else{
add(nd->left,id,namE,surnamE);
}
}
}