#include<stdio.h>
#include<malloc.h>
#include<fcntl.h>
#include<string.h>
int num(char *num)
{
int dec = 0, i, j, len;
len = strlen(num);
for(i=0; i<len; i++){
dec = dec * 10 + ( num[i] - '0'
);
}
return dec;
}
struct node
{
int data;
struct node *left;
struct node *right;
};
struct node *tree;
void create(struct node *tree)
{
tree=NULL;
}
struct node *TREE_INSERT(struct node *tree,int val)
{
struct node *ptr,*nodeptr,*parentptr;
ptr=(struct node *)malloc(sizeof(struct node));
ptr->data=val;
ptr->left=NULL;
ptr->right=NULL;
if(tree==NULL)
{
tree=ptr;
tree->left=NULL;
tree->right=NULL;
}
else
{
parentptr=NULL;
nodeptr=tree;
while(nodeptr!=NULL)
{
parentptr=nodeptr;
if(val<nodeptr->data)
nodeptr=nodeptr->left;
else
nodeptr=nodeptr->right;
}
if(val<parentptr->data)
parentptr->left=ptr;
else
parentptr->right=ptr;
}
return tree;
}
void INORDER_TREE_WALK(struct node *tree)
{
if(tree!=NULL)
{
inorder(tree->left);
printf("%d ",tree->data);
inorder(tree->right);
}
}
int main()
{
int n,i,count=0;
char buf[2];
int fd=open("name.txt",777);
while(read(fd,buf,1)!='\0')
{
if(buf[0]=='\n')
count++;
}
close(fd);
fd=open("name.txt",777);
int arr[count];
create(tree);
for(i=0;i<count;i++)
{
read(fd,buf,1);
int t=num(buf[0]);
tree=TREE_INSERT(tree,t);
}
INORDER_TREE_WALK(tree);
return 0;
}
3 Programming Question (45 points) 3.1 Instructions You need to write the code by yourself. Your...
All commands must be in the command line. The expense data file is separate. Programming Project #2: Manage Spending Using Commands Objectives: • Understand how to create and manipulate list of objects using array or vector class • Handle input errors and invalid values • Design and create a well-structure program using C++ basic programming constructs and classes. Description: Each “expense” contains 2 values: the spending amount (double) and its description (string) Here is an example of the “expense” data...
Question:Many files on our computers, such as executables and many music and video files, are binary files (in contrast to text files). The bytes in these files must be interpreted in ways that depend on the file format. In this exercise, we write a program data-extract to extract integers from a file and save them to an output file. The format of the binary files in this exercise is very simple. The file stores n integers (of type int). Each...
Homework description::::: Write JAVA program with following description. Sample output with code will be helful... A compiler must examine tokens in a program and decide whether they are reserved words in the Java language, or identifiers defined by the user. Design a program that reads a Java program and makes a list of all the identifiers along with the number of occurrences of each identifier in the source code. To do this, you should make use of a dictionary. The...
I need help with this code,
I'm stuck on it, please remember step 4, I'm very much stuck on
that part. It says something about putting how many times it
appears
Assignment #1: Sorting with Binary Search Tree Through this programming assignment, the students will learn to do the following: Know how to process command line arguments. 1 Perform basic file I/O. 2. Use structs, pointers, and strings. Use dynamic memory. 3. 4. This assignment asks you to sort the...
#1 To execute a correctly written program, you first need to _____. highlight the output commands in the code print the code for reference compile it to machine language compile it from machine language into the programming language of choice #2 Adding capabilities to working software is called the _____ phase. coding maintenance debugging brainstorming #3 A rectangle in a flowchart represents which of the following? One or more I/Os ...
Edit a C program based on the surface code(which is after the question's instruction.) that will implement a customer waiting list that might be used by a restaurant. Use the base code to finish the project. When people want to be seated in the restaurant, they give their name and group size to the host/hostess and then wait until those in front of them have been seated. The program must use a linked list to implement the queue-like data structure....
n this programming assignment, you need to create 3 files. 1. DateType.h 2. DateType.cpp 3. A test driver for testing the class defined in the other 2 files. You can name your file in the way you like. Remember it must be a .cpp file. In DateType.h file, type these lines: // To declare a class for the Date ADT // This is the header file DateType.h class DateType { public: void Initialize(int newMonth, int newDay, int newYear); int GetYear()...
FIRST: Write code that prompts the user for the name of a text file, opens that file if it exists and reads the file one line at a time printing each line to the screen. You must implement the file read in a try/catch block rather than throwing the exception on the main method. NEXT: Modify your code so that the program takes the name of two files from the command line, opens the first file if it exists for...
*Help Please with the code**
CSIT 345 Lab 2 Process Programming Your lab requirement is to write program codes for 3.21 and shared memory program for producer and consumer as shown in the following. You can start with the code provided in the virtual machine in the virtual box you installed. The code can be found in /home/oscreader/osc9e-src/ch3 a. For 3.21, you can start with the newprocposix.c and modify the code to meet your requirement. Then type: gcc neypCOCROSİS.c to...