1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
antoniya [11.8K]
3 years ago
13

In this part, you have to implement a linked list that maintains a list of integers in sorted order. Thus, if the list contains

2, 5 and 8, then 1 will be inserted at the start of the list, 3 will be inserted between 2 and 5 and 10 will be inserted at the end. The list can contain duplicate elements. 1 Input format: This program takes a le name as an argument from the command line. The le is either blank or contains successive lines of input. Each line contains a character, either `i' or `d', followed by a tab character and then an integer. For each of the lines that starts with `i', your program should insert that number in the linked list in sorted order. If it is already there, your program can insert it before or after the existing entry. If the line starts with a `d', your program should delete the rst value if it is present in the linked list. If there are duplicates your program must delete just the rst occurrence of the value. Your program should silently ignore the line if the requested value is not present in the linked list.
Computers and Technology
1 answer:
kupik [55]3 years ago
7 0

Answer:

#include <stdio.h>   // header file

#include <stdlib.h>

struct node{    //define structure "node"

int data;

struct node* next;    // object

};

struct node* add(struct node* head, int num);

struct node* delete(struct node* head, int num);

void print(struct node* head);

int size(struct node* head);

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

FILE *fp = NULL;

struct node* head = NULL;

int num;

char command;

if(argc != 2){

printf("Please provide input filename as a command line argument\n");

return 1;

}

fp = fopen(argv[1], "r");

if(fp == NULL){

printf("error\n");

return 1;

}

fscanf(fp, "%c %d", &command, &num);

while(!feof(fp)){

if(command == 'i')

head = add(head, num);

else if(command == 'd')

head = delete(head, num);

fscanf(fp, "%c %d", &command, &num);

}

fclose(fp);

printf("%d\n",size(head));

print(head);

}

struct node* add(struct node* head, int num){

struct node* prev = NULL;

struct node* curr = head;

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

n->data = num;

n->next = NULL;

while(curr != NULL){

if(num < curr->data) //found a place to insert

break;

else if(num == curr->data) //duplicate

return head;

prev = curr;

curr = curr->next;

}

n->next = curr;

if(prev != NULL)

prev->next = n;

else

head = n;

return head;

}

struct node* delete(struct node* head, int num){

struct node* prev = NULL;

struct node* curr = head;

while(curr != NULL){

if(num < curr->data)

return head;

else if(num == curr->data)

break;

prev = curr;

curr = curr->next;

}

if(curr == NULL) //did not find

return head;

if(prev == NULL) //remove 1st node

head = curr->next;

else

prev->next = curr->next;

free(curr);

return head;

}

void print(struct node* head)

{

struct node* curr = head;

if(head != NULL){

printf("%d", curr->data);

curr = curr->next;

while(curr != NULL){

printf("\t%d", curr->data);

curr = curr->next;

}

}

printf("\n");

}

int size(struct node* head){

struct node* curr = head;

int count = 0;

while(curr != NULL){

count++;

curr = curr->next;

}

return count;

}

Output:

Provide input filename as a command-line argument

Test2 sg$ ./.s.out in.txt

2  5  8

1  2  3  5  10

Test2 sg$  

Explanation:

we create a link list of integer in sorted order then if we input as 2  5  8, then 1  insert at the starting of the list and 3 in middle of 2 and 5 and 10 is inserted at the last.

You might be interested in
4. Software, biotechnology, and information technology hardware industries are examples of the type of knowledge industry A.mana
motikmotik
D.Has knowledge as its product?

6 0
3 years ago
The software application associated with a specific file type is called a(n) __________ application.
tresset_1 [31]
I believe it’s a default application.
6 0
3 years ago
Homework Assignment 2 1. Consider the skeletal definition for a class called circle given as: public class Circle { private int
jek_recluse [69]

Answer:

See explaination

Explanation:

public class Circle {

private double radius;

private Location location;

private String name;

/* (non-Javadoc)

* atsee java.lang.Object#hashCode()

*/

atOverride

public int hashCode() {

final int prime = 31;

int result = 1;

result = prime * result + ((location == null) ? 0 : location.hashCode());

long temp;

temp = Double.doubleToLongBits(radius);

result = prime * result + (int) (temp ^ (temp >>> 32));

return result;

}

/* (non-Javadoc)

* atsee java.lang.Object#equals(java.lang.Object)

*/

atOverride

public boolean equals(Object obj) {

if (this == obj)

return true;

if (obj == null)

return false;

if (getClass() != obj.getClass())

return false;

Circle other = (Circle) obj;

if (location == null) {

if (other.location != null)

return false;

} else if (!location.equals(other.location))

return false;

if (Double.doubleToLongBits(radius) != Double.doubleToLongBits(other.radius))

return false;

return true;

}

NOTE: Replace all the "at" within the program with the at symbol ie shift 2.

3 0
3 years ago
La sección de lectores de un diario de la ciudad impone como única restricción para la publicación de las cartas, que el texto d
kap26 [50]

Answer:

El tamaño de un archivo .txt que contenga esa cantidad de texto será de 1.46 KB.

Explanation:

Se entiende que todo caracter informático posee un tamaño de 1 byte, con lo cual en total el texto no puede superar los 1,500 bytes de tamaño.

Ahora bien, un kilobyte es una unidad de medida informática superior, que se compone de 1,024. Por lo tanto, dado que 1,500 - 1,024 es igual a 474, el tamaño del archivo será de 1 KB y 474 bytes. Así, para calcular el tamaño total del archivo en KB, se debe realizar el siguiente cálculo:

1,024 = 1

474 = X

((474 x 1) / 1,024) = X

0.46 = X

Así, el tamaño de un archivo .txt que contenga esa cantidad de texto será de 1.46 KB.

4 0
3 years ago
Microsoft sql server, oracle, db2 are examples of:_____.
Sloan [31]

Oracle, DB2, and Microsoft SQL Server are examples of RDBMS. Therefore, the <u>correct option of this question is (c)</u> i.e. RDBMS.

A software used to store, query, and retrieve data stored in a relational database is referred to as a relational database management system (RDBMS). In RDBMS, data is represented in tables with rows and columns.

The RDBMS handles administrative functions such as managing data access, storage and performance. To perform these administrative services, RDBMS provides an interface between the database, applications and users.

Some features of RDBMS are described below:

  1. RDBMSs are more secure, faster and easier to work with.
  2. More than one user can have access to RDBMS at a point of time.
  3. RDBMS supports distributed databases.
  4. RDBMS can store a vast amount of data.
  5. Only the data in the form of tables is managed by RDBMS.
  6. Data redundancy is reduced in RDBMS using primary keys and indexes.

Thus, Oracle, DB2, and Microsoft sql server are example of RDBMS.

<u>While the other ptions (a) supply chain management and (b) erp applications are not correct because:</u>

  • Supply chain management is a centralized management process that handles the flow of goods and services, such as movement and storage of raw materials, inventory, finished goods, and delivery of the final product.
  • Enterprise resource planning (ERP) applications refers to software used in organizations to manage day-to-day business operations such as project management, risk management and compliance, procurement, accounting and supply chain operations.

You can learn more about relational databases at

brainly.com/question/13262352

#SPJ4

7 0
1 year ago
Other questions:
  • Given the following code, find the compile error.
    12·1 answer
  • Which of the following may present a problem for Linux users?
    13·2 answers
  • What is a computer that provides services and connections to other computers on a network is called a ________ ?
    7·1 answer
  • What is a bug?
    11·2 answers
  • In addition to MLA, what are some other widely used style guides? Check all that apply.
    5·1 answer
  • In the following scenario, which is the least
    8·1 answer
  • Digital information is stored using a series of ones and zeros. Computers are digital machines because they can only read inform
    11·2 answers
  • What would the internet be like today if there was no World Wide Web?
    9·1 answer
  • I know that this will be taken down for not being a real question but is anyone else not able to search for anything? I can type
    13·1 answer
  • 25 points select 3 options!!!!!!!!!!!!!!!!!!!!!!!!!
    5·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!