Program In C You are required to write an interactive C program that prompts the user for
commands, accepts commands from the keyboard (stdin) and executes those commands. When a
command requires output, it must be written to stdout. The program must continue to accept and
process commands until the user types the end command ourput, it must be writen to stdout. The
program must continue to accept and proces.commands The program deals with linked lists.
Each node of such a list contains a string of length at most 10, a positive integer (i.e., an integer
value 2 1) and a pointer to the next node of the list. For any node, the string and the integer
stored in that node will be referred to as the symbol and count for that node respectively. At all
times, the list must satisfy the following two important properties. 1. The symbols appearing in
the list are all distinct; that is, no two nodes have the same symbol. 2. When the list is scanned
from left to right, the counts must be in non-increasing order. An example of such a linked list is
shown below. Search 4 Maxval4 begin/ Loop head
Solution
/**********************************************/
/****** NAMES ******************** COMMANDS ***/
/* Insert Command : ins str */
/* Delete Command : del str */
/* Forced Delete Command : fde val */
/* Print Statistics Command : pst */
/* Print List Command : prl */
/* Print using Count Range Command: pcr v1 v2 */
/* Print Prefix Command : ppr str */
/* Print Suffix Command : psu str */
/* End Command : end */
/***********************************************/
#include
#include
#include
#define CSIZE 4
#define SSIZE 11
/* Struct for each node in the linked list */
struct node
{
int count;
char symbol[SSIZE];
struct node *next;
};
struct node *head;
/* Prototypes for the functions */
void insert(char *);
void delete(char *);
void forced_delete(int value);
void print_stats();
void print_list();
void print_count(int, int);
void print_prefix(char pre[]);
void print_suffix(char suf[]);
void sort_list();
/****************
** Main Method **
****************/
int main(void)
{
int count;
char symbol[SSIZE];
char cmd[CSIZE];
int v1;
int v2;
/* Enter commands */
printf(\"Command? \"); fflush(stdout);
scanf(\"%s\", cmd);
/* Check for command*/
while(strcmp(cmd,\"end\") != 0)
{
/* check which function to use */
if(strcmp(cmd,\"ins\") == 0) { scanf(\"%s\", symbol); insert(symbol); }
if(strcmp(cmd,\"del\") == 0) { scanf(\"%s\", symbol); delete(symbol); }
else if(strcmp(cmd,\"fde\")==0){scanf(\"%d\",&count); forced_delete(count); }
if(strcmp(cmd,\"pst\") == 0) { print_stats();}
if(strcmp(cmd,\"prl\") == 0) { print_list(); }
if(strcmp(cmd,\"pcr\") == 0) { scanf(\"%d %d\",&v1,&v2); print_count(v1,v2); }
if(strcmp(cmd,\"ppr\") == 0) { scanf(\"%s\", symbol); print_prefix(symbol);}
if(strcmp(cmd,\"psu\") == 0) { scanf(\"%s\", symbol); print_suffix(symbol);}
printf(\"Command? \"); fflush(stdout);
scanf(\"%s\", cmd);
}// End of While Loop
return 0;
}// End of main method
/*********.
I am Gabriel C. I am a C Exam Expert at programmingexamhelp.com. I hold a PhD. in Business analyst of Information Technology, Montreal College of Information Technology, Canada. I have been helping students with their exams for the past 8 years. You can hire me to take your exam in C.
Visit programmingexamhelp.com or email support@programmingexamhelp.com. You can also call on +1 678 648 4277 for any assistance with the C Exam.
-- Task 2- Debugging a program with stacks- queues- and doubly-linked.docxAdamq0DJonese
/* Task 2: Debugging a program with stacks, queues, and doubly-linked lists There are a number of errors in the following program. All errors are located in main() and structure definitions. Function declarations and definitions are correct! Locate all errors, fix them (as shown below), run the program and save its output as a comment at the end of the source file. Example: int num = 10; int *ptr; num = &ptr; // <== Error: Comment the line and write the correct line below // Write a short justification where appropriate // num = &ptr; // Error #1 ptr = # Name: */ #include #include #include #include #define DUMMY_TRAILER '\177' // octal ASCII code of the // last character in the ASCII table #define NUM_CITIES 10 typedef struct { char name[12]; int temperature[5]; } CITY; // Stack and Queue Node typedef struct node NODE; struct node { CITY city; node *next; }; // Doubly Linked List Node typedef struct d_node D_NODE; struct d_node { CITY city; NODE *forw; NODE *back; }; // Stack Functions NODE *push(NODE *stack, const CITY *pStu); NODE *pop(NODE **stack); // Queue Functions void enqueue(NODE **queue, NODE **rear, const CITY *pStu); NODE *dequeue(NODE **queue, NODE **rear); // Doubly Linked List Functions D_NODE *init_list(void); int insert(D_NODE *list, const CITY *pStu); void traverse_forw(D_NODE *list); void traverse_back(D_NODE *list); // Other Functions void printCity(const CITY *pCity); int main (void) { CITY cList[NUM_CITIES] = { {"Cupertino", {88, 89, 87, 85, 89}}, {"Flagstaff", {81, 80, 88, 89, 89}}, {"Los Angeles", {87, 88, 89, 89, 90}}, {"Philadelphia", {96, 99, 99, 90, 95}}, {"Phoenix", {106, 109, 109, 100, 105}}, {"Portland", {89, 90, 85, 89, 90}}, {"Reno", {108, 105, 109, 100, 108}}, {"Salem", {85, 90, 85, 89, 90}}, {"Tucson", {107, 100, 109, 100, 108}}, {"Yreka", {101, 109, 100, 108, 109}} }; NODE *stack = NULL; NODE *top = NULL; NODE *queue = NULL, *rear = NULL; NODE *front; D_NODE *list; list = init_list(); // build stack and queue with data from an array of CITY structures srand((unsigned int)time(NULL)); int count = rand() % 10; for ( int n = 0; n < count; n++) { int i = rand() % NUM_CITIES; int duplicate = insert(list, &cList[i]); if(duplicate) { // already in the list! push(stack, &cList[i]); enqueue(&queue, &rear, cList[i]); } } // display list printf("\nLIST contents (forwards):\n"); traverse_forw(list); printf("\nLIST contents (backwards):\n"); traverse_back(list); // display stack if (top) { printf("\nSTACK contents from top to bottom:\n"); while ((top = pop(stack))) { printCity(top->city); } } else printf ("Empty Stack!\n"); // display queue if (front) { printf("\nQUEUE contents from front to rear:\n"); while ((front = dequeue( queue, rear))) { printCity(front->city); } } else printf ("Empty Queue!\n"); return 0; } /*************************************************** Displays the fileds of a CIS_CLASS structure Pre pCls - a pointer to a CIS_CLASS structure Post */ void printCity(const CITY *pCity) { printf("%-20s %3d\n",.
There are a number of errors in the following program- All errors are.docxclarkjanyce
There are a number of errors in the following program.
All errors are located in main() and structure definitions.
Function declarations and definitions are correct!
Locate all errors, fix them (as shown below), run the program and save its output
as a comment at the end of the source file.
Example:
int num = 10;
int *ptr;
num = &ptr; // <== Error: Comment the line and write the correct line below
// Write a short justification where appropriate
// num = &ptr; // Error #1
ptr = #
Name:
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#define DUMMY_TRAILER '\177'
// octal ASCII code of the
// last character in the ASCII table
#define NUM_CITIES 10
typedef struct
{
char name[12];
int temperature[5];
} CITY;
// Stack and Queue Node
typedef struct node NODE;
struct node
{
CITY city;
node *next;
};
// Doubly Linked List Node
typedef struct d_node D_NODE;
struct d_node
{
CITY city;
NODE *forw;
NODE *back;
};
// Stack Functions
NODE *push(NODE *stack, const CITY *pStu);
NODE *pop(NODE **stack);
// Queue Functions
void enqueue(NODE **queue, NODE **rear, const CITY *pStu);
NODE *dequeue(NODE **queue, NODE **rear);
// Doubly Linked List Functions
D_NODE *init_list(void);
int insert(D_NODE *list, const CITY *pStu);
void traverse_forw(D_NODE *list);
void traverse_back(D_NODE *list);
// Other Functions
void printCity(const CITY *pCity);
int main (void)
{
CITY cList[NUM_CITIES] =
{
{"Cupertino", {88, 89, 87, 85, 89}},
{"Flagstaff", {81, 80, 88, 89, 89}},
{"Los Angeles", {87, 88, 89, 89, 90}},
{"Philadelphia", {96, 99, 99, 90, 95}},
{"Phoenix", {106, 109, 109, 100, 105}},
{"Portland", {89, 90, 85, 89, 90}},
{"Reno", {108, 105, 109, 100, 108}},
{"Salem", {85, 90, 85, 89, 90}},
{"Tucson", {107, 100, 109, 100, 108}},
{"Yreka", {101, 109, 100, 108, 109}}
};
NODE *stack = NULL;
NODE *top = NULL;
NODE *queue = NULL, *rear = NULL;
NODE *front;
D_NODE *list;
list = init_list();
// build stack and queue with data from an array of CITY structures
srand((unsigned int)time(NULL));
int count = rand() % 10;
for ( int n = 0; n < count; n++)
{
int i = rand() % NUM_CITIES;
int duplicate = insert(list, &cList[i]);
if(duplicate)
{
// already in the list!
push(stack, &cList[i]);
enqueue(&queue, &rear, cList[i]);
}
}
// display list
printf("\nLIST contents (forwards):\n");
traverse_forw(list);
printf("\nLIST contents (backwards):\n");
traverse_back(list);
// display stack
if (top)
{
printf("\nSTACK contents from top to bottom:\n");
while ((top = pop(stack)))
{
printCity(top->city);
}
}
else
printf ("Empty Stack!\n");
// display queue
if (front)
{
printf("\nQUEUE contents from front to rear:\n");
while ((front = dequeue( queue, rear)))
{
printCity(front->city);
}
}
else
printf ("Empty Queue!\n");
return 0;
}
/***************************************************
Displays the fileds of a CIS_CLASS structure
Pre pCls - a pointer to a CIS_CLASS structure
Post
*/
void printCity(const CITY *pCity)
{
printf("%-20s %3d\n", pCity->name, pCity->temperatur.
I am Andrew O. I am a C Homework Expert at programminghomeworkhelp.com. I hold a master’s in Programming from, the University of Southampton, UK. I have been helping students with their homework for the past 10 years. I solve homework related to C.
Visit programminghomeworkhelp.com or email support@programminghomeworkhelp.com.
You can also call on +1 678 648 4277 for any assistance with C Homework.
C++ Doubly-Linked ListsThe goal of the exercise is to implement a.pdfpoblettesedanoree498
C++: Doubly-Linked Lists
The goal of the exercise is to implement a class List of doubly- linked lists.
My goal is to implement the class in a file doubly-linked.cpp.
The class List implements lists using the following structures for list ele- ments:
struct Node { int val ;
Node next;
Node prev; };
Each Node contains a value (an integer) and two pointers: one meant to point to the next element
of the list and one meant to point to the previous element in the list. The class provides the
following methods that you need to implement:
• A constructor and a destructor, with no arguments;
• void insert(int n): insert an integer at the end of the list;
• void reverse(): reverse the list;
• void print(): print the list to cout in the same format as the input (i.e. integers separated by
spaces);
doubly-linked.h
#ifndef __dll__
#define __dll__
#include
using namespace std;
// Basic structure to store elements of a list
struct Node {
int val; // contains the value
Node * next; // pointer to the next element in the list
Node * prev; // pointer to the previous element in the list
};
// Class List
class List {
public:
List(void); // Constructor
~List(void); // Destructor
void insert(int n); // This should insert n in the list
void reverse(void); // This should reverse the list
void print(void); // This shoiuld print the list
private:
Node * first; // Pointer to the first (if any) element in the list
};
#endif
main.cpp
#include
#include \"doubly-linked.h\"
using namespace std;
int main(void){
List l;
int n;
while(cin >> n){
l.insert(n);
}
// Print list as read from cin
l.print();
// Reverse the list and print it
l.reverse();
l.print();
// Reverse again and print it
l.reverse();
l.print();
return 0;
}
Solution
#include
using namespace std;
/* Linked list structure */
struct list {
struct list *prev;
int data;
struct list *next;
} *node = NULL, *first = NULL, *last = NULL, *node1 = NULL, *node2 = NULL;
class linkedlist {
public:
/* Function for create/insert node at the beginning of Linked list */
void insrt_frnt() {
list *addBeg = new list;
cout << \"Enter value for the node:\" << endl;
cin >> addBeg->data;
if(first == NULL) {
addBeg->prev = NULL;
addBeg->next = NULL;
first = addBeg;
last = addBeg;
cout << \"Linked list Created!\" << endl;
}
else {
addBeg->prev = NULL;
first->prev = addBeg;
addBeg->next = first;
first = addBeg;
cout << \"Data Inserted at the beginning of the Linked list!\" << endl;
}
}
/* Function for create/insert node at the end of Linked list */
void insrt_end() {
list *addEnd = new list;
cout << \"Enter value for the node:\" << endl;
cin >> addEnd->data;
if(first == NULL) {
addEnd->prev = NULL;
addEnd->next = NULL;
first = addEnd;
last = addEnd;
cout << \"Linked list Created!\" << endl;
}
else {
addEnd->next = NULL;
last->next = addEnd;
addEnd->prev = last;
last = addEnd;
cout << \"Data Inserted at the end of the Linked list!\" << endl;
}
}
/* Function for Display Linked list */
void display() {
node = first;
cout << \"List of data in L.
Merge Sort implementation in C++ The implementation for Mergesort gi.pdfmdameer02
Merge Sort implementation in C++ The implementation for Mergesort given in Section 7.4 takes
an array as input and soils that array. At the beginning of Section 7.4 there is a simple
pseudocode implementation for sorting a linked list using Mergesort. Implement both a linked
list-based version of Mergesort and the array-based version of Mergesort. and compare and
analyze their running times.
Solution
/* Merger sort array-based version */
/* C program for Merge Sort */
#include
#include
// Merges two subarrays of arr[].
// First subarray is arr[l..m]
// Second subarray is arr[m+1..r]
void merge(int arr[], int l, int m, int r)
{
int i, j, k;
int n1 = m - l + 1;
int n2 = r - m;
/* create temp arrays */
int L[n1], R[n2];
/* Copy data to temp arrays L[] and R[] */
for (i = 0; i < n1; i++)
L[i] = arr[l + i];
for (j = 0; j < n2; j++)
R[j] = arr[m + 1+ j];
/* Merge the temp arrays back into arr[l..r]*/
i = 0; // Initial index of first subarray
j = 0; // Initial index of second subarray
k = l; // Initial index of merged subarray
while (i < n1 && j < n2)
{
if (L[i] <= R[j])
{
arr[k] = L[i];
i++;
}
else
{
arr[k] = R[j];
j++;
}
k++;
}
/* Copy the remaining elements of L[], if there
are any */
while (i < n1)
{
arr[k] = L[i];
i++;
k++;
}
/* Copy the remaining elements of R[], if there
are any */
while (j < n2)
{
arr[k] = R[j];
j++;
k++;
}
}
/* l is for left index and r is right index of the
sub-array of arr to be sorted */
void mergeSort(int arr[], int l, int r)
{
if (l < r)
{
// Same as (l+r)/2, but avoids overflow for
// large l and h
int m = l+(r-l)/2;
// Sort first and second halves
mergeSort(arr, l, m);
mergeSort(arr, m+1, r);
merge(arr, l, m, r);
}
}
/* UTILITY FUNCTIONS */
/* Function to print an array */
void printArray(int A[], int size)
{
int i;
for (i=0; i < size; i++)
printf(\"%d \", A[i]);
printf(\"\ \");
}
/* Driver program to test above functions */
int main()
{
int arr[] = {12, 11, 13, 5, 6, 7};
int arr_size = sizeof(arr)/sizeof(arr[0]);
printf(\"Given array is \ \");
printArray(arr, arr_size);
mergeSort(arr, 0, arr_size - 1);
printf(\"\ Sorted array is \ \");
printArray(arr, arr_size);
return 0;
}
--------------------------------------------------------------------------------------------------------------------
/* merge sort link-list version
#include
#include
/* Link list node */
struct node
{
int data;
struct node* next;
};
/* function prototypes */
struct node* SortedMerge(struct node* a, struct node* b);
void FrontBackSplit(struct node* source,
struct node** frontRef, struct node** backRef);
/* sorts the linked list by changing next pointers (not data) */
void MergeSort(struct node** headRef)
{
struct node* head = *headRef;
struct node* a;
struct node* b;
/* Base case -- length 0 or 1 */
if ((head == NULL) || (head->next == NULL))
{
return;
}
/* Split head into \'a\' and \'b\' sublists */
FrontBackSplit(head, &a, &b);
/* Recursively sort the sublists */
MergeSort(&a);
MergeSort(&b);
/* answer = merge the two sorted lists together */
*.
I am Gabriel C. I am a C Exam Expert at programmingexamhelp.com. I hold a PhD. in Business analyst of Information Technology, Montreal College of Information Technology, Canada. I have been helping students with their exams for the past 8 years. You can hire me to take your exam in C.
Visit programmingexamhelp.com or email support@programmingexamhelp.com. You can also call on +1 678 648 4277 for any assistance with the C Exam.
-- Task 2- Debugging a program with stacks- queues- and doubly-linked.docxAdamq0DJonese
/* Task 2: Debugging a program with stacks, queues, and doubly-linked lists There are a number of errors in the following program. All errors are located in main() and structure definitions. Function declarations and definitions are correct! Locate all errors, fix them (as shown below), run the program and save its output as a comment at the end of the source file. Example: int num = 10; int *ptr; num = &ptr; // <== Error: Comment the line and write the correct line below // Write a short justification where appropriate // num = &ptr; // Error #1 ptr = # Name: */ #include #include #include #include #define DUMMY_TRAILER '\177' // octal ASCII code of the // last character in the ASCII table #define NUM_CITIES 10 typedef struct { char name[12]; int temperature[5]; } CITY; // Stack and Queue Node typedef struct node NODE; struct node { CITY city; node *next; }; // Doubly Linked List Node typedef struct d_node D_NODE; struct d_node { CITY city; NODE *forw; NODE *back; }; // Stack Functions NODE *push(NODE *stack, const CITY *pStu); NODE *pop(NODE **stack); // Queue Functions void enqueue(NODE **queue, NODE **rear, const CITY *pStu); NODE *dequeue(NODE **queue, NODE **rear); // Doubly Linked List Functions D_NODE *init_list(void); int insert(D_NODE *list, const CITY *pStu); void traverse_forw(D_NODE *list); void traverse_back(D_NODE *list); // Other Functions void printCity(const CITY *pCity); int main (void) { CITY cList[NUM_CITIES] = { {"Cupertino", {88, 89, 87, 85, 89}}, {"Flagstaff", {81, 80, 88, 89, 89}}, {"Los Angeles", {87, 88, 89, 89, 90}}, {"Philadelphia", {96, 99, 99, 90, 95}}, {"Phoenix", {106, 109, 109, 100, 105}}, {"Portland", {89, 90, 85, 89, 90}}, {"Reno", {108, 105, 109, 100, 108}}, {"Salem", {85, 90, 85, 89, 90}}, {"Tucson", {107, 100, 109, 100, 108}}, {"Yreka", {101, 109, 100, 108, 109}} }; NODE *stack = NULL; NODE *top = NULL; NODE *queue = NULL, *rear = NULL; NODE *front; D_NODE *list; list = init_list(); // build stack and queue with data from an array of CITY structures srand((unsigned int)time(NULL)); int count = rand() % 10; for ( int n = 0; n < count; n++) { int i = rand() % NUM_CITIES; int duplicate = insert(list, &cList[i]); if(duplicate) { // already in the list! push(stack, &cList[i]); enqueue(&queue, &rear, cList[i]); } } // display list printf("\nLIST contents (forwards):\n"); traverse_forw(list); printf("\nLIST contents (backwards):\n"); traverse_back(list); // display stack if (top) { printf("\nSTACK contents from top to bottom:\n"); while ((top = pop(stack))) { printCity(top->city); } } else printf ("Empty Stack!\n"); // display queue if (front) { printf("\nQUEUE contents from front to rear:\n"); while ((front = dequeue( queue, rear))) { printCity(front->city); } } else printf ("Empty Queue!\n"); return 0; } /*************************************************** Displays the fileds of a CIS_CLASS structure Pre pCls - a pointer to a CIS_CLASS structure Post */ void printCity(const CITY *pCity) { printf("%-20s %3d\n",.
There are a number of errors in the following program- All errors are.docxclarkjanyce
There are a number of errors in the following program.
All errors are located in main() and structure definitions.
Function declarations and definitions are correct!
Locate all errors, fix them (as shown below), run the program and save its output
as a comment at the end of the source file.
Example:
int num = 10;
int *ptr;
num = &ptr; // <== Error: Comment the line and write the correct line below
// Write a short justification where appropriate
// num = &ptr; // Error #1
ptr = #
Name:
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#define DUMMY_TRAILER '\177'
// octal ASCII code of the
// last character in the ASCII table
#define NUM_CITIES 10
typedef struct
{
char name[12];
int temperature[5];
} CITY;
// Stack and Queue Node
typedef struct node NODE;
struct node
{
CITY city;
node *next;
};
// Doubly Linked List Node
typedef struct d_node D_NODE;
struct d_node
{
CITY city;
NODE *forw;
NODE *back;
};
// Stack Functions
NODE *push(NODE *stack, const CITY *pStu);
NODE *pop(NODE **stack);
// Queue Functions
void enqueue(NODE **queue, NODE **rear, const CITY *pStu);
NODE *dequeue(NODE **queue, NODE **rear);
// Doubly Linked List Functions
D_NODE *init_list(void);
int insert(D_NODE *list, const CITY *pStu);
void traverse_forw(D_NODE *list);
void traverse_back(D_NODE *list);
// Other Functions
void printCity(const CITY *pCity);
int main (void)
{
CITY cList[NUM_CITIES] =
{
{"Cupertino", {88, 89, 87, 85, 89}},
{"Flagstaff", {81, 80, 88, 89, 89}},
{"Los Angeles", {87, 88, 89, 89, 90}},
{"Philadelphia", {96, 99, 99, 90, 95}},
{"Phoenix", {106, 109, 109, 100, 105}},
{"Portland", {89, 90, 85, 89, 90}},
{"Reno", {108, 105, 109, 100, 108}},
{"Salem", {85, 90, 85, 89, 90}},
{"Tucson", {107, 100, 109, 100, 108}},
{"Yreka", {101, 109, 100, 108, 109}}
};
NODE *stack = NULL;
NODE *top = NULL;
NODE *queue = NULL, *rear = NULL;
NODE *front;
D_NODE *list;
list = init_list();
// build stack and queue with data from an array of CITY structures
srand((unsigned int)time(NULL));
int count = rand() % 10;
for ( int n = 0; n < count; n++)
{
int i = rand() % NUM_CITIES;
int duplicate = insert(list, &cList[i]);
if(duplicate)
{
// already in the list!
push(stack, &cList[i]);
enqueue(&queue, &rear, cList[i]);
}
}
// display list
printf("\nLIST contents (forwards):\n");
traverse_forw(list);
printf("\nLIST contents (backwards):\n");
traverse_back(list);
// display stack
if (top)
{
printf("\nSTACK contents from top to bottom:\n");
while ((top = pop(stack)))
{
printCity(top->city);
}
}
else
printf ("Empty Stack!\n");
// display queue
if (front)
{
printf("\nQUEUE contents from front to rear:\n");
while ((front = dequeue( queue, rear)))
{
printCity(front->city);
}
}
else
printf ("Empty Queue!\n");
return 0;
}
/***************************************************
Displays the fileds of a CIS_CLASS structure
Pre pCls - a pointer to a CIS_CLASS structure
Post
*/
void printCity(const CITY *pCity)
{
printf("%-20s %3d\n", pCity->name, pCity->temperatur.
I am Andrew O. I am a C Homework Expert at programminghomeworkhelp.com. I hold a master’s in Programming from, the University of Southampton, UK. I have been helping students with their homework for the past 10 years. I solve homework related to C.
Visit programminghomeworkhelp.com or email support@programminghomeworkhelp.com.
You can also call on +1 678 648 4277 for any assistance with C Homework.
C++ Doubly-Linked ListsThe goal of the exercise is to implement a.pdfpoblettesedanoree498
C++: Doubly-Linked Lists
The goal of the exercise is to implement a class List of doubly- linked lists.
My goal is to implement the class in a file doubly-linked.cpp.
The class List implements lists using the following structures for list ele- ments:
struct Node { int val ;
Node next;
Node prev; };
Each Node contains a value (an integer) and two pointers: one meant to point to the next element
of the list and one meant to point to the previous element in the list. The class provides the
following methods that you need to implement:
• A constructor and a destructor, with no arguments;
• void insert(int n): insert an integer at the end of the list;
• void reverse(): reverse the list;
• void print(): print the list to cout in the same format as the input (i.e. integers separated by
spaces);
doubly-linked.h
#ifndef __dll__
#define __dll__
#include
using namespace std;
// Basic structure to store elements of a list
struct Node {
int val; // contains the value
Node * next; // pointer to the next element in the list
Node * prev; // pointer to the previous element in the list
};
// Class List
class List {
public:
List(void); // Constructor
~List(void); // Destructor
void insert(int n); // This should insert n in the list
void reverse(void); // This should reverse the list
void print(void); // This shoiuld print the list
private:
Node * first; // Pointer to the first (if any) element in the list
};
#endif
main.cpp
#include
#include \"doubly-linked.h\"
using namespace std;
int main(void){
List l;
int n;
while(cin >> n){
l.insert(n);
}
// Print list as read from cin
l.print();
// Reverse the list and print it
l.reverse();
l.print();
// Reverse again and print it
l.reverse();
l.print();
return 0;
}
Solution
#include
using namespace std;
/* Linked list structure */
struct list {
struct list *prev;
int data;
struct list *next;
} *node = NULL, *first = NULL, *last = NULL, *node1 = NULL, *node2 = NULL;
class linkedlist {
public:
/* Function for create/insert node at the beginning of Linked list */
void insrt_frnt() {
list *addBeg = new list;
cout << \"Enter value for the node:\" << endl;
cin >> addBeg->data;
if(first == NULL) {
addBeg->prev = NULL;
addBeg->next = NULL;
first = addBeg;
last = addBeg;
cout << \"Linked list Created!\" << endl;
}
else {
addBeg->prev = NULL;
first->prev = addBeg;
addBeg->next = first;
first = addBeg;
cout << \"Data Inserted at the beginning of the Linked list!\" << endl;
}
}
/* Function for create/insert node at the end of Linked list */
void insrt_end() {
list *addEnd = new list;
cout << \"Enter value for the node:\" << endl;
cin >> addEnd->data;
if(first == NULL) {
addEnd->prev = NULL;
addEnd->next = NULL;
first = addEnd;
last = addEnd;
cout << \"Linked list Created!\" << endl;
}
else {
addEnd->next = NULL;
last->next = addEnd;
addEnd->prev = last;
last = addEnd;
cout << \"Data Inserted at the end of the Linked list!\" << endl;
}
}
/* Function for Display Linked list */
void display() {
node = first;
cout << \"List of data in L.
Merge Sort implementation in C++ The implementation for Mergesort gi.pdfmdameer02
Merge Sort implementation in C++ The implementation for Mergesort given in Section 7.4 takes
an array as input and soils that array. At the beginning of Section 7.4 there is a simple
pseudocode implementation for sorting a linked list using Mergesort. Implement both a linked
list-based version of Mergesort and the array-based version of Mergesort. and compare and
analyze their running times.
Solution
/* Merger sort array-based version */
/* C program for Merge Sort */
#include
#include
// Merges two subarrays of arr[].
// First subarray is arr[l..m]
// Second subarray is arr[m+1..r]
void merge(int arr[], int l, int m, int r)
{
int i, j, k;
int n1 = m - l + 1;
int n2 = r - m;
/* create temp arrays */
int L[n1], R[n2];
/* Copy data to temp arrays L[] and R[] */
for (i = 0; i < n1; i++)
L[i] = arr[l + i];
for (j = 0; j < n2; j++)
R[j] = arr[m + 1+ j];
/* Merge the temp arrays back into arr[l..r]*/
i = 0; // Initial index of first subarray
j = 0; // Initial index of second subarray
k = l; // Initial index of merged subarray
while (i < n1 && j < n2)
{
if (L[i] <= R[j])
{
arr[k] = L[i];
i++;
}
else
{
arr[k] = R[j];
j++;
}
k++;
}
/* Copy the remaining elements of L[], if there
are any */
while (i < n1)
{
arr[k] = L[i];
i++;
k++;
}
/* Copy the remaining elements of R[], if there
are any */
while (j < n2)
{
arr[k] = R[j];
j++;
k++;
}
}
/* l is for left index and r is right index of the
sub-array of arr to be sorted */
void mergeSort(int arr[], int l, int r)
{
if (l < r)
{
// Same as (l+r)/2, but avoids overflow for
// large l and h
int m = l+(r-l)/2;
// Sort first and second halves
mergeSort(arr, l, m);
mergeSort(arr, m+1, r);
merge(arr, l, m, r);
}
}
/* UTILITY FUNCTIONS */
/* Function to print an array */
void printArray(int A[], int size)
{
int i;
for (i=0; i < size; i++)
printf(\"%d \", A[i]);
printf(\"\ \");
}
/* Driver program to test above functions */
int main()
{
int arr[] = {12, 11, 13, 5, 6, 7};
int arr_size = sizeof(arr)/sizeof(arr[0]);
printf(\"Given array is \ \");
printArray(arr, arr_size);
mergeSort(arr, 0, arr_size - 1);
printf(\"\ Sorted array is \ \");
printArray(arr, arr_size);
return 0;
}
--------------------------------------------------------------------------------------------------------------------
/* merge sort link-list version
#include
#include
/* Link list node */
struct node
{
int data;
struct node* next;
};
/* function prototypes */
struct node* SortedMerge(struct node* a, struct node* b);
void FrontBackSplit(struct node* source,
struct node** frontRef, struct node** backRef);
/* sorts the linked list by changing next pointers (not data) */
void MergeSort(struct node** headRef)
{
struct node* head = *headRef;
struct node* a;
struct node* b;
/* Base case -- length 0 or 1 */
if ((head == NULL) || (head->next == NULL))
{
return;
}
/* Split head into \'a\' and \'b\' sublists */
FrontBackSplit(head, &a, &b);
/* Recursively sort the sublists */
MergeSort(&a);
MergeSort(&b);
/* answer = merge the two sorted lists together */
*.
File name a2.cppTaskFor this assignment, you are required to ei.pdfinfomalad
File name: a2.cpp
Task
For this assignment, you are required to either A) modify your linked list code to implement a
queue or B) modify the provided stack code to implement a queue. Your program should
implement a C++ queue class with the following member functions:
- Void enq(int)
- Void deq()
- Void front()
- Bool isEmpty()
- Void printq()
Your program will take in a command file called “cmd.txt” which will instruct your program
what operations to run
File Format
<0 or 1 arguments>
Commands
- 1 enq
- 2 deq
- 3 front
- 4 isEmpty
- 5 printq
Example File
1 1
5
1 2
5
1 3
5
1 4
5
3
2
5
2
5
3
Expectations
You should not use any already pre implemented code for your queue such as a standard library
object
Your code should be well formatted with proper spacing and proper naming
Your code should have well named variables. No a’s b’s or c’s as names unless it is for
something like a loop counter
Your code should have the same output formatting you see below
Your code MUST follow the formatting you see below
Your file MUST be named a2.cpp
My example file does not contain all possible test cases it is up to you to determine any other
special cases to test your program against.
Example Output
//LinkedList class
#include
#include
#include
#include
#include
using namespace std;
struct Node
{
int data;
Node *next;
};
class LinkedList
{
private:
Node *head;
Node *tail;
public:
LinkedList(); //constructor
void prepend(int num);
void append(int num);
void removeFront();
void removeBack();
void remove(int num);
int search(int num);
void printList();
};
//constructor
LinkedList::LinkedList()
{
head=NULL;
tail=NULL;
}
//prepend() method
void LinkedList::prepend(int num)
{
//allocate space for new node
Node *node=new Node;
//populate node
node->data=num;
node->next= NULL;
//attach new node to start of list
//if linked list empty
if(head==NULL)
{
head=node;
tail=node;
}
else //linked list not empty
{
node->next=head;
head=node;
}
}
//append() method
void LinkedList::append(int num)
{
//allocate space for new node
Node *node=new Node;
//populate node
node->data=num;
node->next= NULL;
//attach new node to end of list
//if linked list empty
if(head==NULL)
{
head=node;
tail=node;
}
else //linked list not empty
{
tail->next=node;
tail=node;
}
}
//removeFront() method
void LinkedList::removeFront()
{
//if linked list empty, then underflow
if(head==NULL)
{
cerr<<\"Underflow\"<next;
//delete node
cout<<\"Removing \"<data<<\" from the list\"<next!=NULL)
{
/*if(curr==tail)
break;*/
prev=curr;
curr=curr->next;
}
prev->next=NULL;
tail=prev;
//delete node
cout<<\"Removing \"<data<<\" from the list\"<data=num)
break;
prev=curr;
curr=curr->next;
}
//preserve node
Node *temp=curr;
//detach node from linked list
prev->next=curr->next;
//delete node
cout<<\"Removing \"<data<<\" from the list\"<data=num)
{
found=1; //num found
break;
}
curr=curr->next;
}
return found;
}
//printList() method
void LinkedList::printList()
{
//traverse linked list
Node *curr=head;
while(curr!=NULL)
{
c.
coding in C- Create a function called reverseList that takes the head.docxtienlivick
coding in C;
Create a function called reverseList that takes the head of a linked list, reverses the order of all the nodes. For example, if the list contained 1, 2, 3, 4 in its nodes, the list will now contain 4, 3, 2, 1.
please add a main test.
Solution
Please find the required program below:
#include<stdio.h>
#include<stdlib.h>
struct node
{
int data;
struct node* next;
};
void push(struct node** head, int new_element)
{
struct node* new_node =
(struct node*) malloc(sizeof(struct node));
new_node->data = new_element;
new_node->next = (*head);
(*head) = new_node;
}
void printList(struct node *head)
{
struct node *temp = head;
while(temp != NULL)
{
printf(\"%d \", temp->data);
temp = temp->next;
}
}
void reverseList(struct node** head)
{
struct node* prev = NULL;
struct node* current = *head;
struct node* next;
while (current != NULL)
{
next = current->next;
current->next = prev;
prev = current;
current = next;
}
*head = prev;
}
int main()
{
struct node* head = NULL;
push(&head, 12);
push(&head, 14);
push(&head, 5);
push(&head, 8);
printf(\"\ Linked list Before Reversing :\ \");
printList(head);
reverseList(&head);
printf(\"\ Linked list After Reversing :\ \");
printList(head);
}
--------------------------------------------------------------------------------
OUTPUT:
Linked list Before Reversing :
8Â Â 5Â Â 14Â Â 12
Linked list After Reversing :
12Â Â 14Â Â 5Â Â 8
.
How do you stop infinite loop Because I believe that it is making a.pdffeelinggift
How do you stop infinite loop? Because I believe that it is making an infinite circular list.
c++ code:
Here is the list class:
#ifndef LIN_J_LIST
#define LIN_J_LIST
typedef unsigned int uint;
#include
#include
using namespace std;
/**
* a simplified generic singly linked list class to illustrate C++ concepts
* @author Jerry Lin
* @version 2/17/17
*/
template< typename Object >
class List
{
private:
/**
* A class to store data and provide a link to the next node in the list
*/
class Node
{
public:
/**
* The constructor
* @param data the data to be stored in this node
*/
explicit Node( const Object & data )
: data{ data }, next{ nullptr } {}
Object data;
Node * next;
};
public:
/**
* The constructor for an empty list
*/
List()
: size{ 0 }, first{ nullptr }, last{ nullptr } {}
/**
* the copy constructor-creates and copy the list
*/
List( List && rhs ) = delete;
List( const List & rhs )
{
count = 0;
size = 0;
if(rhs.size != 0)
{
push_front(rhs.front());
Node * current = rhs.first;
Node * tempNode = first;
size++;
while(current->next != nullptr)
{
current = current->next;
Node *newNode = new Node(current->data); //transfer the data. basic op.
count++;
tempNode->next = newNode;
last = newNode;
tempNode = tempNode->next;
size++;
}
}
// you document and implement this method
}
/**
* the operator= method-copies the list
*/
List & operator=( List && rhs) = delete;
List & operator=( const List & rhs )
{
count = 0;
size = 0;
if( size != 0 )
{
Node * current = first;
Node * temp;
while( current != nullptr )
{
temp = current;
current = current->next;
delete temp;
}
}
if(rhs.size!= 0)
{
push_front(rhs.front());
Node * current = rhs.first;
Node * tempNode = first; //create a temporary to store
size++;
while(current -> next != nullptr)
{
current = current->next;
Node *newNode = new Node(current->data); //transfer the data. basic op
count++;
tempNode->next = newNode;
last = newNode;
tempNode = tempNode -> next;
size++;
}
}
return *this;
// you document and implement this method
}
/**
* accessor
* @return count
*/
int get_count() const
{
return count;
}
/**
* The destructor that gets rid of everything that\'s in the list and
* resets it to empty. If the list is already empty, do nothing.
*/
~List()
{
if( size != 0 )
{
Node * current = first;
Node * temp;
while( current != nullptr )
{
temp = current;
current = current->next;
delete temp;
}
}
}
/**
* Put a new element onto the beginning of the list
* @param item the data the new element will contain
*/
void push_front( const Object& item )
{
Node * new_node = new Node( item );//basic op.
if(is_empty())
{
last = new_node;
}
else
{
new_node->next = first;
}
first = new_node;
size++;
/* you complete the rest */
}
/**
* Remove the element that\'s at the front of the list. Causes an
* assertion error if the list is empty.
*/
void pop_front()
{
assert( !is_empty() );
Node * temp = first;
if( first == last )
{
first = last = nullptr;
}
else
{
first = first->next;
}
delete temp;
size--;
}
/**
* Accessor to return the da.
write recursive function that calculates and returns the length of a.pdfarpitcomputronics
write recursive function that calculates and returns the length of a linked list
Solution
// C code to determine length of linked list recursively
#include
#include
// node of linked list
struct node
{
int key;
struct node* next;
};
// push key to linked list
void push(struct node** root, int new_element)
{
struct node* nodeNew = (struct node*) malloc(sizeof(struct node));
nodeNew->key = new_element;
nodeNew->next = (*root);
(*root) = nodeNew;
}
// recursively get length of linked list
int lengthLinkedlist(struct node* root)
{
// base case
if (root == NULL)
return 0;
// recursively call the function
return 1 + lengthLinkedlist(root->next);
}
int main()
{
struct node* root = NULL;
push(&root, 11);
push(&root, 34);
push(&root, 4);
push(&root, 23);
push(&root, 14);
push(&root, 88);
push(&root, 56);
push(&root, 84);
push(&root, 6);
/* Check the count function */
printf(\"Length of Linked list: %d\ \", lengthLinkedlist(root));
return 0;
}
/*
output:
Length of Linked list: 9
*/.
Using the provided table interface table.h and the sample linked lis.pdfconnellalykshamesb60
Using the provided table interface table.h and the sample linked list code linkedList.c, complete
an implementation of the Table ADT. Make sure that you apply the concepts of design by
contract (DbC) to your implementation.
Once you have fully implemented the table, create a main.c file that implements a testing
framework for your table.
Your table implementation must ensure that values inserted are unique, and internally sorted
within a linked list.
table.h
linkedList.c
Solution
khsdg
#include
#include
typedef enum BOOL { false, true } bool;
// Linked list node definition
typedef struct Node node;
struct Node
{
int number;
node *next;
};
static node *top = NULL;
// used to track where we are for the list traversal methods
static node *traverseNode = NULL;
// \"destroy\" will deallocate all nodes in a linked list object
// and will set \"top\" to NULL.
void destroy()
{
node *curr = top;
node *temp = NULL;
while ( curr != NULL )
{
// flip order to see it blow up...
temp = curr;
curr = curr->next;
free( temp );
}
top = NULL;
}
// \"build\" will create an ordered linked list consisting
// of the first \"size\" even integers.
void build( int size )
{
node *newNode = NULL;
int i = 0;
// make sure we don\'t have a list yet
destroy();
for ( i=size ; i>0 ; i-- )
{
newNode = malloc( sizeof( node ) );
newNode->number = i*2;
newNode->next = top;
top = newNode;
}
}
// starts a list traversal by getting the data at top.
// returns false if top == NULL.
bool firstNode( int *item )
{
bool result = false;
if ( top )
{
*item = top->number;
traverseNode = top->next;
result = true;
}
return result;
}
// gets the data at the current traversal node and increments the traversal.
// returns false if we\'re at the end of the list.
bool nextNode( int *item )
{
bool result = false;
if ( traverseNode )
{
*item = traverseNode->number;
traverseNode = traverseNode->next;
result = true;
}
return result;
}
// \"print\" will output an object\'s entire linked list
// to the standard output device -- one \"number\" per line.
void print()
{
int value;
if ( firstNode( &value ) )
{
do
{
printf( \"%d\ \", value );
} while ( nextNode( &value ) );
}
}
int main( int argc, char *argv[] )
{
build( 10 );
print();
destroy();
build( 5 );
build( 20 );
print();
destroy();
return 0;
}.
For this homework, you will write a program to create and manipulate.pdfherminaherman
For this homework, you will write a program to create and manipulate a simple linked list. For
each node in the linked list you will generate a random number, create a node that holds that
number, and insert that node into its sorted position in the linked list. Once the nodes are
inserted, you will traverse the list, printing the value held in each node. Then you will clean up
the list (deleting all the nodes) and exit the program. You will also learn about a tool that you can
use to help you check for memory errors in your code.
Specifications:
Define a struct appropriate for holding a random integer. This struct will also contain a \"next\"
pointer to reference a separate instance of the struct.
You may use the typedef keyword to give your struct a separate typename if you wish, but this is
not a requirement.
The program will read command line arguments. The first argument is the program name (as it
will always be) followed by a random number seed, the number of random numbers to generate
and ending with the Maximum Possible Value of the Random numbers generated (i.e. argc
should be 4).
Your program will use a \"dummy node\" for the linked list. In other words, the head of the list
will be an actual node, but the data field in that node will not be used for sorting purposes.
Your program must contain the following functions:
main() (for obvious reasons)
insertNodeSorted() - You may implement this either of two ways.
One way is to use the head of the list as one parameter and the integer value as the second. The
function will allocate memory for the node, initialize it and then insert it in the proper location in
the list.
The other way is to pass the head of the list as one parameter and a previously allocated and
initialized node as the other. The existing node is inserted in the proper location in the list.
printList() - Takes the head of the list as its only parameter, traverses the list, printing out the
data in sorted order.
deleteList() - Takes the head of the list as its only parameter, traverses the list, deleting all nodes.
The basic algorithm of your program is
Use a loop (based upon command line input values) that:
Generates a random number
Prints the number to stdout
Creates a node that contains that random number
Inserts the new node in sorted order into the existing list
Print the sorted linked list
Delete the linked list
You will use a Makefile to compile your program
Solution
#include
#include
#include
struct test_struct
{
int val;
struct test_struct *next;
};
struct test_struct *head = NULL;
struct test_struct *curr = NULL;
struct test_struct* create_list(int val)
{
printf(\"\ creating list with headnode as [%d]\ \",val);
struct test_struct *ptr = (struct test_struct*)malloc(sizeof(struct test_struct));
if(NULL == ptr)
{
printf(\"\ Node creation failed \ \");
return NULL;
}
ptr->val = val;
ptr->next = NULL;
head = curr = ptr;
return ptr;
}
struct test_struct* add_to_list(int val, bool add_to_end)
{
if(NULL == head)
{
retur.
Write a C++ program 1. Study the function process_text() in file.pdfjillisacebi75827
Write a C++ program
1. Study the function process_text() in file \"text_processing.cpp\". What do the string member
functions find(), substr(), c_str() do?
//text_processing.cpp
#include \"util.h\"
#include \"text_processing.h\"
#include
using namespace std;
int process_text( fstream &ifs, fstream &ofs, char target[] )
{
string replace_str( \"XXX\" ); //hard-coded string for replacement
int tlen = strlen( target ); //string length of target
int max_len = 200; //maximum length of a line
char s[max_len+1];
clear_screen(); //clear the screen
while ( !ifs.eof() ) {
int i2, i1 = 0, len=0;
ifs.getline( s, max_len ); //get one line from file
string str( s ); //construct a string object
i2 = str.find ( target, i1 ); //find target
len = i2 - i1;
if ( i2 > -1 && len > 0 ){ //if target found
print_text( str.substr( i1, i2 ).c_str() ); //print up to target
ofs << str.substr( i1, i2 );
}
while ( i2 > -1 ) {
print_text_inverse ( target ); //highlight target
ofs << replace_str;
i1 = i2 + tlen; //new search position
i2 = str.find ( target, i1 ); //find next target
len = i2 - i1;
if ( i2 > -1 && len > 0 ){ //found target
print_text( str.substr( i1, len ).c_str() ); //print up to target
ofs << str.substr( i1, len );
}
}
len = str.length() - i1;
if ( len > 0 ) { //print the remainder
print_text( str.substr( i1, len ).c_str() );
ofs << str.substr( i1, len );
}
ofs << endl;
getnstr( s, 1 ); //prompt for
} //while ( !ifs.eof() )
restore_screen(); //restore the old screen
return 1;
}
//text_processing.h
#ifndef TEXT_PROCESSING_H
#define TEXT_PROCESSING_H
#include
#include
using namespace std;
int process_text( fstream &ifs, fstream &ofs, char target[] );
#endif
//util.h
#ifndef UTIL_H
#define UTIL_H
#include
#include
#include
#include
#include
using namespace std;
void usage ( char program_name[] );
void clear_screen();
void print_text( const char *s );
void print_text_inverse( const char *s );
void get_input_text( char *s, int max_len );
void restore_screen();
#endif
//util.cpp
#include \"util.h\"
void usage ( char program_name[] )
{
cout << \"Usage: \" << program_name << \" infile outfile search_string\" << endl;
return;
}
/*
The following are some curses functions. You can find
the details by the command \"man ncurses\". But its use
can be transparent to you.
*/
void clear_screen()
{
initscr();
scrollok ( stdscr, true ); //allow window to scroll
}
void print_text ( const char *s )
{
printw(\"%s\", s );
refresh();
}
void print_text_inverse( const char *s )
{
attron( A_REVERSE );
printw(\"%s\", s );
attroff( A_REVERSE );
refresh();
}
void get_input_text( char *s, int max_len )
{
getnstr( s, max_len );
}
void restore_screen()
{
endwin();
}
//str_main.cpp
#include \"util.h\"
#include \"text_processing.h\"
#include
using namespace std;
/*
Note that grace_open() must be defined in same file
as main(), otherwise the destructor of fstream will
automatically close the opened file as it finds that
its out of scope upon exiting the function.
*/
int grace_open( char *s, fst.
I need to fill-in TODOs in .cpp file and in .h file Could some.pdfforladies
I need to fill-in //TODO\'s in .cpp file and in .h file
Could someone help me at least with few of them to give me an idea how deal with it.
***SinglyLinkedList.cpp
#include
#include
#include \"SinglyLinkedList.h\"
void test_constructor() {
SinglyLinkedList lst = {100, 200, 300, 400, 500};
assert(*lst.at(0) == 100);
assert(*lst.at(1) == 200);
assert(*lst.at(2) == 300);
assert(*lst.at(3) == 400);
assert(*lst.at(4) == 500);
assert(lst.size() == 5);
}
void test_remove() {
SinglyLinkedList lst = {100, 200, 300, 400, 500};
lst.remove(2);
assert(*lst.at(0) == 100);
assert(*lst.at(1) == 200);
assert(*lst.at(2) == 400);
assert(*lst.at(3) == 500);
assert(lst.size() == 4);
}
void test_insert() {
// TODO
}
void test_push_back() {
// TODO
}
void test_push_front() {
// TODO
}
void test_append() {
// TODO
}
void test_sum() {
// TODO
}
int main() {
test_constructor();
test_remove();
test_insert();
test_push_back();
test_push_front();
test_append();
test_sum();
}
***SinglyLinkedList.h
#include
#include
template
class SinglyLinkedList {
// Nested class representing the nodes in the list.
class SinglyLinkedListNode {
public:
// The value stored in this node.
T value;
// The next node in the sequence.
SinglyLinkedListNode *next;
SinglyLinkedListNode(T value) :
value(value), next(nullptr) {}
SinglyLinkedListNode(T value, SinglyLinkedListNode *next) :
value(value), next(next) {}
// Return the size (length) of the linked list.
std::size_t size();
};
SinglyLinkedListNode *head;
SinglyLinkedListNode *tail;
public:
// Constructs a new SinglyLinkedList from an initializer_list of type T[].
// This is mostly for convenience, especially when testing.
SinglyLinkedList(std::initializer_list items) : head(nullptr), tail(nullptr) {
if (items.size() == 0) {
return;
}
// initializer_lists were designed to be used iteratively,
// so thats what we do.
// Can you think of how to write this recursively?
auto it = items.begin();
while (it != items.end()) {
this->push_back(*it++);
}
}
// Return a pointer to the value at the given index.
// If the index is larger than the size of the list,
// return a nullptr.
//
// ASIDE: We will cover exceptions later.
T* at(std::size_t i);
// Pushes a new node onto the back of the list.
void push_back(T value);
// Pushes a new node onto the front of the list.
void push_front(T value);
// Return the size (length) of the linked list.
std::size_t size();
// Remove the specified node from the list.
void remove(std::size_t i);
// Insert the value at the index.
void insert(std::size_t i, T value);
// Append the given list to this one.
void append(SinglyLinkedList list);
};
template
T* SinglyLinkedList::at(std::size_t i) {
// TODO
}
template
void SinglyLinkedList::push_back(T value) {
// TODO
// Make sure that this is a O(1) operation!
}
template
void SinglyLinkedList::push_front(T value) {
// TODO
// Make sure that this is a O(1) operation!
}
template
void SinglyLinkedList::remove(std::size_t i) {
// TODO
// Don\'t forget to not only unlink the node, b.
Write a program that accepts an arithmetic expression of unsigned in.pdfJUSTSTYLISH3B2MOHALI
Write a program that accepts an arithmetic expression of unsigned integers in postfix notation
and builds the arithmetic expression tree that represents that expression. From that tree, the
corresponding fully parenthesized infix expression should be displayed and a file should be
generated that contains the three address format instructions. This topic is discussed in the week
4 reading in module 2, section II-B. The main class should create the GUI shown below:
Pressing the Construct Tree button should cause the tree to be constructed and using that tree, the
corresponding infix expression should be displayed and the three address instruction file should
be generated. The postfix expression input should not be required to have spaces between every
token. Note in the above example that 9+- are not separated by spaces. The above example
should produce the following output file containing the three address instructions:
Add R0 5 9
Sub R1 3
R0 Mul R2 2 3
Div R3 R1 R2
Inheritance should be used to define the arithmetic expression tree. At a minimum, it should
involve three classes: an abstract class for the tree nodes and two derived classes, one for
operand nodes and another for operator nodes. Other classes should be included as needed to
accomplish good object-oriented design. All instance data must be declared as private.
You may assume that the expression is syntactically correct with regard to the order of operators
and operands, but you should check for invalid tokens, such as characters that are not valid
operators or operands such as 2a, which are not valid integers. If an invalid token is detected a
RuntimeException should be thrown and caught by the main class and an appropriate error
message should be displayed. Three Adddress Generator Enter Postfix Expression 359 2 3
Construct Tree Infix Expression ((3-(5 9))/ (2* 3
Solution
#include
#include
#include
#include
#include
struct TREE //Structure to represent a tree
{
char data;
struct TREE *right,*left,*root;
};
typedef TREE tree; /* Stack Using Linked List */
struct Stack //Structure to represent Stack
{
struct TREE *data;
struct Stack *next,*head,*top; //Pointers to next node,head and top
};
typedef struct Stack node;
node *Nw; //Global Variable to represent node
void initialize(node *&n)
{
n = new node;
n -> next = n -> head = n -> top = NULL;
}
void create(node *n)
{
Nw = new node; //Create a new node
Nw -> next = NULL; //Initialize next pointer field
if(n -> head == NULL) //if first node
{
n -> head = Nw; //Initialize head
n -> top = Nw; //Update top
}
}
void push(node *n,tree *ITEM)
{
node *temp = n -> head;
if(n -> head == NULL) //if First Item is Pushed to Stack
{
create(n); //Create a Node
n -> head -> data = ITEM; //Insert Item to head of List
n -> head = Nw;
return; //Exit from Function
}
create(n); //Create a new Node
Nw -> data = ITEM; //Insert Item
while(temp -> next != NULL)
temp = temp -> next; //Go to Last Node
temp -> next = Nw; //Point New node
n -> top = Nw; //Upda.
THE CODE HAS A SEGMENTATION FAULT BUT I CANNOT FIND OUT WHERE. NEED .pdffathimahardwareelect
THE CODE HAS A SEGMENTATION FAULT BUT I CANNOT FIND OUT WHERE. NEED
HELP FIXING THIS CODE?
THIS IS THE PROBLEM
Write a program that allows the user to enter two positive integers and outputs their sum. Sounds
simple? Here\'s the catch: The numbers may be any size! They may be way too large to store in a
single variable. You may not assume any particular maximum number of digits.
HERE IS THE CODE
#include
#include
struct node /* Linked list node*/
{
int data;
struct node* next;
};
struct node *newNode(int data) /* Function to create a new node with giving the data*/
{
struct node *new_node = (struct node *) malloc(sizeof(struct node));
new_node->data = data;
new_node->next = NULL;
return new_node;
}
void push(struct node** head_ref, int new_data) /* Function to insert a node at the beginning of
the Doubly Linked List*/
{
struct node* new_node = newNode(new_data); /*allocate a node*/
new_node->next = (*head_ref); /* link the old list off to the new node*/
(*head_ref) = new_node; /*move the head to point to the new node*/
}
/* Adding the contents of two linked lists and return the head node of resultant list*/
struct node* addTwoLists (struct node* first, struct node* second)
{
struct node* res = NULL; /* res is head node of the resultant list*/
struct node *temp, *prev = NULL;
int carry = 0, sum;
while (first != NULL || second != NULL) /*while both the lists exists*/
{
/* Calculate value of next digit in resultant list.
// The next digit is sum of following things
// (i) Carry
// (ii) Next digit of first list (if there is a next digit)
// (ii) Next digit of second list (if there is a next digit)*/
sum = carry + (first? first->data: 0) + (second? second->data: 0);
carry = (sum >= 10)? 1 : 0; /* update carry for next calulation*/
sum = sum % 10; /*update sum if it is greater than 10*/
temp = newNode(sum); /*Create a new node with sum as data*/
if(res == NULL) /*if this is the first node then set it as head of the resultant list*/
res = temp;
else /* If this is not the first node then connect it to the rest.*/
prev->next = temp;
prev = temp; /* Set prev for next insertion*/
if (first) first = first->next; /* Move first pointers to next node*/
if (second) second = second->next; /*Move second pointer to the next node*/
}
if (carry > 0)
temp->next = newNode(carry);
return res; /* return head of the resultant list*/
}
void printList(struct node *node) /* function to print a linked list*/
{
while(node != NULL)
{
printf(\"%d \", node->data);
node = node->next;
}
printf(\"\ \");
}
int main(void) /* program to test above function*/
{
struct node* res = NULL;
struct node* first = NULL;
struct node* second = NULL;
printf(\"Enter first positive integer: \");
scanf(\"%d\",&first);
printList(first);
printf(\"Enter second positive integer: \");
scanf(\"%d\",&second);
printList(second);
/*Add the two lists and see result*/
res = addTwoLists(first, second);
printf(\"Sum is: %d\");
printList(res);
return 0;
}
Solution
#include
#include
typedef struct Node
{
int da.
The Morse code (see Table 6.10 in book) is a common code that is use.pdfbhim1213
The Morse code (see Table 6.10 in book) is a common code that is used to encode messages
consisted of letters and digits. Each letter consists of a series of dots and dashes; for example, the
code for the letter a is *- and the code for the letter b is -***. Store each letter of the alphabet in a
node of a binary tree of level 5. The root node is at level 1 and stores no letter. The left node at
level 2 stores the letter e (code is *), and the right node stores letter t (code is -). The 4 nodes at
level 3 store the letters with codes (**, *-, -*, --). To build the tree (see Figure 6.38 in book),
read a file in which each line consists of a letter followed by its code. The letters should be
ordered by tree level. To find the position for a letter in the tree, scan the code and branch left for
a dot and branch right for a dash. Encode a message by replacing each letter by its code symbol.
Then decode the message using the Morse code tree. Make sure you use a delimiter symbol
between coded letters.
Implementation Notes: You will need to complete the generic implementation of the BinaryTree
data structure first (see slides). Once it is complete, solve the problem above (note that the book
uses dots and dashes, we will use the asterisk (*) as the dot, hyphen (-) as a dash, and space ( ) as
the delimiter symbol between coded letters). Provide a menu program that asks the user to 1) test
output for all morse code letters with their respective translated alphabet letters (make sure you
are using the binary tree to do the actual translation, output as a nicely formatted table), 2) enter
an input file name to decode morse code and output the translated text to the screen, or 3) enter
in a line of morse code through the console to decode morse code and output the translated text
to the screen
relevenat picture of both the tree diagram and the table of morse code
Solution
JAVA CODE:
import java.io.*;
import java.util.*;
public class MorseCoder implements MorseCodeInterface {
private MorseNode root;
/**
* constructor to build the tree
*/
public MorseCoder() {
root = new MorseNode();
readTreeInfo();
}
/**
* reads in the tree info from the text file (helper method)
*/
private void readTreeInfo() {
Scanner input = null;
try {
input = new Scanner(new File(\"encodings.txt\"));
} catch (FileNotFoundException exception) {
System.out.println(\"File not found!\");
}
while (input.hasNextLine()) {
String data = input.nextLine().trim();
if (data.length() > 0) {
add(data.substring(1).trim(), data.charAt(0));
}
}
input.close();
}
/**
* adds the letter to the tree based on the mcode string (helper method)
* @param mcode the string being fed in
* @param ltr the letter being added at the node
*/
private void add(String mcode, char ltr) {
MorseNode current = root;
String signal = \" \";
for (int i = 0; i < mcode.length(); i++) {
signal = mcode.substring(i, i + 1);
if (signal.equals(\".\")) {
if (current.getLeft() != null) {
current = current.getLeft();
} else {
current.set.
Discuss about Header Node And also write a program for unordered si.pdfeyevision3
Consider rectangle ABCD. If mADF=60°, then what is the mFDC?
a) 60°
b) 30°
c) 90°
d) 120°
e) 45°
f) None of the above
Solution
Given figure ABCD is a rectangle.
Looking into the properties of rectangle,
1) All the angles in a rectangle are right angles i.e. equal to 90 degrees.
2) Opposite sides are parallel and equal.
By the first property stated above,
m(D) = 90 degrees
Angle D can be written as given in the following
m(D) = m(ADF) + m(FDC) = 90
Given m(ADF) = 60
Therefore, 60 + m(FDC) = 90
m(FDC) = 30 degress.
Hence option B) 30 is the required answer..
Describe the role of soil microbes in the formation and maintenance .pdfamitbagga0808
Describe the role of soil microbes in the formation and maintenance of water-stable soil
aggregates. Can you identify two mechanisms through which soil microbes contribute to the
formation and stabilization of such aggregates?
soild science
Solution
Formation and maintenance ofwater-stable solid aggregates in the soil are important parts of soil
formation and tillage. The microorganisms play a very important role in it. The microbes
normally reside in the soil as a major part of their life cycle. The microbes residing in the soil
perform following function for maintaining soil quality and texture:
1. The microbes survive on soil as a nutrient source. Small microbes such as some bacteria and
fungi absorb nutrients from the soil, digest them in their gut and release the excreta rich in
polysaccharides and polyuronic acids. These polysaccharides are water-stable and thus help in
aggregating small particles of soil and hence bind them.
2. As the microbes gradually complete their life cycle, they die and decay in the soil. As they
decay, the bio-molecules and bio-polymers get assimilated in the soil. Since these microbial bio-
molecules and bio-polymers are rich in water stable compounds,they agglutinate with minute soil
particles to generate water-stable hydrophobic aggregates.
Thus, the two mechanisms can be distinguished as described above as:
1. Release of bio-molecules from microbes
2. Decay and assimilation of microbes in soil
For example: Zygomyceta (vascular arbuscular mycorrhizal fungi) and some bacteria..
Chapter 9Problem P 9-1The narrative and systems flowchart for.pdfamitbagga0808
Chapter 9:
Problem: P 9-1:
The narrative and systems flowchart for the Bridgeport LLC cash
receipts system are included in Exhibit 9.5 and Figure 9.11 (pg. 348),
respectively.
Using Exhibit 9.5 and Figure 9.11, do the following:
a. Prepare a control matrix, including explanations of how each recommended control plan helps
to accomplish? Or would accomplish in
the case of missing plans? Each related control goal. Your choice of
recommended control plans should come from Figure 9.4 (pg. 325)/
Exhibit 9.3 (pp. 329? 330) or Figure 9.6 (pg. 334)/Exhibit 9.4 (pg. 338), as appropriate. Be sure
to tailor the matrix columns to conform to the
specifics of the Bridgeport system. In doing so, assume the following
two effectiveness goals only:
- Timely deposit of checks?
-Compliance with compensating balance agreements with the
depository bank?
Control Goals of the Bridgeport Cash Receipts Process
Control Goals of the Operations Process
Control Goals of the Information Process
Ensure effectiveness of operations:
Ensure efficient employment of resources (people, computers)
Ensure security of resources (cash, accounts receivable master data)
For the remittance advice inputs (i.e., cash receipts), ensure:
For the accounts receivable master data, ensure:
Recommended control plans
A
B
IV
IC
IA
UC
UA
Present Controls
P-1: Turnaround documents
P-2: Endorse checks immediately
P-3: Preformatted screens
P-4: Compare input data with master data
P-5: Programmed edit checks.
P-6: Procedure for rejected inputs
P-7: Manual agreement of RA batch totals
P-8: Manual agreement of deposit batch totals
Missing Controls
M-1: Document design
M-2: Enter cash receipts in the mailroom (enter data close to original source)
M-3: Computer agreement of batch totals
Possible effectiveness goals include the following:
A – Timely deposit of checks
B – Comply with compensating balance agreements with the depository bank
IV = input validity
IC = input completeness
IA = input accuracy
UC = update completeness
UA = update accuracy
Control Goals of the Bridgeport Cash Receipts Process
Control Goals of the Operations Process
Control Goals of the Information Process
Ensure effectiveness of operations:
Ensure efficient employment of resources (people, computers)
Ensure security of resources (cash, accounts receivable master data)
For the remittance advice inputs (i.e., cash receipts), ensure:
For the accounts receivable master data, ensure:
Recommended control plans
A
B
IV
IC
IA
UC
UA
Present Controls
P-1: Turnaround documents
P-2: Endorse checks immediately
P-3: Preformatted screens
P-4: Compare input data with master data
P-5: Programmed edit checks.
P-6: Procedure for rejected inputs
P-7: Manual agreement of RA batch totals
P-8: Manual agreement of deposit batch totals
Missing Controls
M-1: Document design
M-2: Enter cash receipts in the mailroom (enter data close to original source)
M-3: Computer agreement of batch totals
Possible effectiveness goals include the following:
A – Timely deposit.
More Related Content
Similar to Program In C You are required to write an interactive C program that.pdf
File name a2.cppTaskFor this assignment, you are required to ei.pdfinfomalad
File name: a2.cpp
Task
For this assignment, you are required to either A) modify your linked list code to implement a
queue or B) modify the provided stack code to implement a queue. Your program should
implement a C++ queue class with the following member functions:
- Void enq(int)
- Void deq()
- Void front()
- Bool isEmpty()
- Void printq()
Your program will take in a command file called “cmd.txt” which will instruct your program
what operations to run
File Format
<0 or 1 arguments>
Commands
- 1 enq
- 2 deq
- 3 front
- 4 isEmpty
- 5 printq
Example File
1 1
5
1 2
5
1 3
5
1 4
5
3
2
5
2
5
3
Expectations
You should not use any already pre implemented code for your queue such as a standard library
object
Your code should be well formatted with proper spacing and proper naming
Your code should have well named variables. No a’s b’s or c’s as names unless it is for
something like a loop counter
Your code should have the same output formatting you see below
Your code MUST follow the formatting you see below
Your file MUST be named a2.cpp
My example file does not contain all possible test cases it is up to you to determine any other
special cases to test your program against.
Example Output
//LinkedList class
#include
#include
#include
#include
#include
using namespace std;
struct Node
{
int data;
Node *next;
};
class LinkedList
{
private:
Node *head;
Node *tail;
public:
LinkedList(); //constructor
void prepend(int num);
void append(int num);
void removeFront();
void removeBack();
void remove(int num);
int search(int num);
void printList();
};
//constructor
LinkedList::LinkedList()
{
head=NULL;
tail=NULL;
}
//prepend() method
void LinkedList::prepend(int num)
{
//allocate space for new node
Node *node=new Node;
//populate node
node->data=num;
node->next= NULL;
//attach new node to start of list
//if linked list empty
if(head==NULL)
{
head=node;
tail=node;
}
else //linked list not empty
{
node->next=head;
head=node;
}
}
//append() method
void LinkedList::append(int num)
{
//allocate space for new node
Node *node=new Node;
//populate node
node->data=num;
node->next= NULL;
//attach new node to end of list
//if linked list empty
if(head==NULL)
{
head=node;
tail=node;
}
else //linked list not empty
{
tail->next=node;
tail=node;
}
}
//removeFront() method
void LinkedList::removeFront()
{
//if linked list empty, then underflow
if(head==NULL)
{
cerr<<\"Underflow\"<next;
//delete node
cout<<\"Removing \"<data<<\" from the list\"<next!=NULL)
{
/*if(curr==tail)
break;*/
prev=curr;
curr=curr->next;
}
prev->next=NULL;
tail=prev;
//delete node
cout<<\"Removing \"<data<<\" from the list\"<data=num)
break;
prev=curr;
curr=curr->next;
}
//preserve node
Node *temp=curr;
//detach node from linked list
prev->next=curr->next;
//delete node
cout<<\"Removing \"<data<<\" from the list\"<data=num)
{
found=1; //num found
break;
}
curr=curr->next;
}
return found;
}
//printList() method
void LinkedList::printList()
{
//traverse linked list
Node *curr=head;
while(curr!=NULL)
{
c.
coding in C- Create a function called reverseList that takes the head.docxtienlivick
coding in C;
Create a function called reverseList that takes the head of a linked list, reverses the order of all the nodes. For example, if the list contained 1, 2, 3, 4 in its nodes, the list will now contain 4, 3, 2, 1.
please add a main test.
Solution
Please find the required program below:
#include<stdio.h>
#include<stdlib.h>
struct node
{
int data;
struct node* next;
};
void push(struct node** head, int new_element)
{
struct node* new_node =
(struct node*) malloc(sizeof(struct node));
new_node->data = new_element;
new_node->next = (*head);
(*head) = new_node;
}
void printList(struct node *head)
{
struct node *temp = head;
while(temp != NULL)
{
printf(\"%d \", temp->data);
temp = temp->next;
}
}
void reverseList(struct node** head)
{
struct node* prev = NULL;
struct node* current = *head;
struct node* next;
while (current != NULL)
{
next = current->next;
current->next = prev;
prev = current;
current = next;
}
*head = prev;
}
int main()
{
struct node* head = NULL;
push(&head, 12);
push(&head, 14);
push(&head, 5);
push(&head, 8);
printf(\"\ Linked list Before Reversing :\ \");
printList(head);
reverseList(&head);
printf(\"\ Linked list After Reversing :\ \");
printList(head);
}
--------------------------------------------------------------------------------
OUTPUT:
Linked list Before Reversing :
8Â Â 5Â Â 14Â Â 12
Linked list After Reversing :
12Â Â 14Â Â 5Â Â 8
.
How do you stop infinite loop Because I believe that it is making a.pdffeelinggift
How do you stop infinite loop? Because I believe that it is making an infinite circular list.
c++ code:
Here is the list class:
#ifndef LIN_J_LIST
#define LIN_J_LIST
typedef unsigned int uint;
#include
#include
using namespace std;
/**
* a simplified generic singly linked list class to illustrate C++ concepts
* @author Jerry Lin
* @version 2/17/17
*/
template< typename Object >
class List
{
private:
/**
* A class to store data and provide a link to the next node in the list
*/
class Node
{
public:
/**
* The constructor
* @param data the data to be stored in this node
*/
explicit Node( const Object & data )
: data{ data }, next{ nullptr } {}
Object data;
Node * next;
};
public:
/**
* The constructor for an empty list
*/
List()
: size{ 0 }, first{ nullptr }, last{ nullptr } {}
/**
* the copy constructor-creates and copy the list
*/
List( List && rhs ) = delete;
List( const List & rhs )
{
count = 0;
size = 0;
if(rhs.size != 0)
{
push_front(rhs.front());
Node * current = rhs.first;
Node * tempNode = first;
size++;
while(current->next != nullptr)
{
current = current->next;
Node *newNode = new Node(current->data); //transfer the data. basic op.
count++;
tempNode->next = newNode;
last = newNode;
tempNode = tempNode->next;
size++;
}
}
// you document and implement this method
}
/**
* the operator= method-copies the list
*/
List & operator=( List && rhs) = delete;
List & operator=( const List & rhs )
{
count = 0;
size = 0;
if( size != 0 )
{
Node * current = first;
Node * temp;
while( current != nullptr )
{
temp = current;
current = current->next;
delete temp;
}
}
if(rhs.size!= 0)
{
push_front(rhs.front());
Node * current = rhs.first;
Node * tempNode = first; //create a temporary to store
size++;
while(current -> next != nullptr)
{
current = current->next;
Node *newNode = new Node(current->data); //transfer the data. basic op
count++;
tempNode->next = newNode;
last = newNode;
tempNode = tempNode -> next;
size++;
}
}
return *this;
// you document and implement this method
}
/**
* accessor
* @return count
*/
int get_count() const
{
return count;
}
/**
* The destructor that gets rid of everything that\'s in the list and
* resets it to empty. If the list is already empty, do nothing.
*/
~List()
{
if( size != 0 )
{
Node * current = first;
Node * temp;
while( current != nullptr )
{
temp = current;
current = current->next;
delete temp;
}
}
}
/**
* Put a new element onto the beginning of the list
* @param item the data the new element will contain
*/
void push_front( const Object& item )
{
Node * new_node = new Node( item );//basic op.
if(is_empty())
{
last = new_node;
}
else
{
new_node->next = first;
}
first = new_node;
size++;
/* you complete the rest */
}
/**
* Remove the element that\'s at the front of the list. Causes an
* assertion error if the list is empty.
*/
void pop_front()
{
assert( !is_empty() );
Node * temp = first;
if( first == last )
{
first = last = nullptr;
}
else
{
first = first->next;
}
delete temp;
size--;
}
/**
* Accessor to return the da.
write recursive function that calculates and returns the length of a.pdfarpitcomputronics
write recursive function that calculates and returns the length of a linked list
Solution
// C code to determine length of linked list recursively
#include
#include
// node of linked list
struct node
{
int key;
struct node* next;
};
// push key to linked list
void push(struct node** root, int new_element)
{
struct node* nodeNew = (struct node*) malloc(sizeof(struct node));
nodeNew->key = new_element;
nodeNew->next = (*root);
(*root) = nodeNew;
}
// recursively get length of linked list
int lengthLinkedlist(struct node* root)
{
// base case
if (root == NULL)
return 0;
// recursively call the function
return 1 + lengthLinkedlist(root->next);
}
int main()
{
struct node* root = NULL;
push(&root, 11);
push(&root, 34);
push(&root, 4);
push(&root, 23);
push(&root, 14);
push(&root, 88);
push(&root, 56);
push(&root, 84);
push(&root, 6);
/* Check the count function */
printf(\"Length of Linked list: %d\ \", lengthLinkedlist(root));
return 0;
}
/*
output:
Length of Linked list: 9
*/.
Using the provided table interface table.h and the sample linked lis.pdfconnellalykshamesb60
Using the provided table interface table.h and the sample linked list code linkedList.c, complete
an implementation of the Table ADT. Make sure that you apply the concepts of design by
contract (DbC) to your implementation.
Once you have fully implemented the table, create a main.c file that implements a testing
framework for your table.
Your table implementation must ensure that values inserted are unique, and internally sorted
within a linked list.
table.h
linkedList.c
Solution
khsdg
#include
#include
typedef enum BOOL { false, true } bool;
// Linked list node definition
typedef struct Node node;
struct Node
{
int number;
node *next;
};
static node *top = NULL;
// used to track where we are for the list traversal methods
static node *traverseNode = NULL;
// \"destroy\" will deallocate all nodes in a linked list object
// and will set \"top\" to NULL.
void destroy()
{
node *curr = top;
node *temp = NULL;
while ( curr != NULL )
{
// flip order to see it blow up...
temp = curr;
curr = curr->next;
free( temp );
}
top = NULL;
}
// \"build\" will create an ordered linked list consisting
// of the first \"size\" even integers.
void build( int size )
{
node *newNode = NULL;
int i = 0;
// make sure we don\'t have a list yet
destroy();
for ( i=size ; i>0 ; i-- )
{
newNode = malloc( sizeof( node ) );
newNode->number = i*2;
newNode->next = top;
top = newNode;
}
}
// starts a list traversal by getting the data at top.
// returns false if top == NULL.
bool firstNode( int *item )
{
bool result = false;
if ( top )
{
*item = top->number;
traverseNode = top->next;
result = true;
}
return result;
}
// gets the data at the current traversal node and increments the traversal.
// returns false if we\'re at the end of the list.
bool nextNode( int *item )
{
bool result = false;
if ( traverseNode )
{
*item = traverseNode->number;
traverseNode = traverseNode->next;
result = true;
}
return result;
}
// \"print\" will output an object\'s entire linked list
// to the standard output device -- one \"number\" per line.
void print()
{
int value;
if ( firstNode( &value ) )
{
do
{
printf( \"%d\ \", value );
} while ( nextNode( &value ) );
}
}
int main( int argc, char *argv[] )
{
build( 10 );
print();
destroy();
build( 5 );
build( 20 );
print();
destroy();
return 0;
}.
For this homework, you will write a program to create and manipulate.pdfherminaherman
For this homework, you will write a program to create and manipulate a simple linked list. For
each node in the linked list you will generate a random number, create a node that holds that
number, and insert that node into its sorted position in the linked list. Once the nodes are
inserted, you will traverse the list, printing the value held in each node. Then you will clean up
the list (deleting all the nodes) and exit the program. You will also learn about a tool that you can
use to help you check for memory errors in your code.
Specifications:
Define a struct appropriate for holding a random integer. This struct will also contain a \"next\"
pointer to reference a separate instance of the struct.
You may use the typedef keyword to give your struct a separate typename if you wish, but this is
not a requirement.
The program will read command line arguments. The first argument is the program name (as it
will always be) followed by a random number seed, the number of random numbers to generate
and ending with the Maximum Possible Value of the Random numbers generated (i.e. argc
should be 4).
Your program will use a \"dummy node\" for the linked list. In other words, the head of the list
will be an actual node, but the data field in that node will not be used for sorting purposes.
Your program must contain the following functions:
main() (for obvious reasons)
insertNodeSorted() - You may implement this either of two ways.
One way is to use the head of the list as one parameter and the integer value as the second. The
function will allocate memory for the node, initialize it and then insert it in the proper location in
the list.
The other way is to pass the head of the list as one parameter and a previously allocated and
initialized node as the other. The existing node is inserted in the proper location in the list.
printList() - Takes the head of the list as its only parameter, traverses the list, printing out the
data in sorted order.
deleteList() - Takes the head of the list as its only parameter, traverses the list, deleting all nodes.
The basic algorithm of your program is
Use a loop (based upon command line input values) that:
Generates a random number
Prints the number to stdout
Creates a node that contains that random number
Inserts the new node in sorted order into the existing list
Print the sorted linked list
Delete the linked list
You will use a Makefile to compile your program
Solution
#include
#include
#include
struct test_struct
{
int val;
struct test_struct *next;
};
struct test_struct *head = NULL;
struct test_struct *curr = NULL;
struct test_struct* create_list(int val)
{
printf(\"\ creating list with headnode as [%d]\ \",val);
struct test_struct *ptr = (struct test_struct*)malloc(sizeof(struct test_struct));
if(NULL == ptr)
{
printf(\"\ Node creation failed \ \");
return NULL;
}
ptr->val = val;
ptr->next = NULL;
head = curr = ptr;
return ptr;
}
struct test_struct* add_to_list(int val, bool add_to_end)
{
if(NULL == head)
{
retur.
Write a C++ program 1. Study the function process_text() in file.pdfjillisacebi75827
Write a C++ program
1. Study the function process_text() in file \"text_processing.cpp\". What do the string member
functions find(), substr(), c_str() do?
//text_processing.cpp
#include \"util.h\"
#include \"text_processing.h\"
#include
using namespace std;
int process_text( fstream &ifs, fstream &ofs, char target[] )
{
string replace_str( \"XXX\" ); //hard-coded string for replacement
int tlen = strlen( target ); //string length of target
int max_len = 200; //maximum length of a line
char s[max_len+1];
clear_screen(); //clear the screen
while ( !ifs.eof() ) {
int i2, i1 = 0, len=0;
ifs.getline( s, max_len ); //get one line from file
string str( s ); //construct a string object
i2 = str.find ( target, i1 ); //find target
len = i2 - i1;
if ( i2 > -1 && len > 0 ){ //if target found
print_text( str.substr( i1, i2 ).c_str() ); //print up to target
ofs << str.substr( i1, i2 );
}
while ( i2 > -1 ) {
print_text_inverse ( target ); //highlight target
ofs << replace_str;
i1 = i2 + tlen; //new search position
i2 = str.find ( target, i1 ); //find next target
len = i2 - i1;
if ( i2 > -1 && len > 0 ){ //found target
print_text( str.substr( i1, len ).c_str() ); //print up to target
ofs << str.substr( i1, len );
}
}
len = str.length() - i1;
if ( len > 0 ) { //print the remainder
print_text( str.substr( i1, len ).c_str() );
ofs << str.substr( i1, len );
}
ofs << endl;
getnstr( s, 1 ); //prompt for
} //while ( !ifs.eof() )
restore_screen(); //restore the old screen
return 1;
}
//text_processing.h
#ifndef TEXT_PROCESSING_H
#define TEXT_PROCESSING_H
#include
#include
using namespace std;
int process_text( fstream &ifs, fstream &ofs, char target[] );
#endif
//util.h
#ifndef UTIL_H
#define UTIL_H
#include
#include
#include
#include
#include
using namespace std;
void usage ( char program_name[] );
void clear_screen();
void print_text( const char *s );
void print_text_inverse( const char *s );
void get_input_text( char *s, int max_len );
void restore_screen();
#endif
//util.cpp
#include \"util.h\"
void usage ( char program_name[] )
{
cout << \"Usage: \" << program_name << \" infile outfile search_string\" << endl;
return;
}
/*
The following are some curses functions. You can find
the details by the command \"man ncurses\". But its use
can be transparent to you.
*/
void clear_screen()
{
initscr();
scrollok ( stdscr, true ); //allow window to scroll
}
void print_text ( const char *s )
{
printw(\"%s\", s );
refresh();
}
void print_text_inverse( const char *s )
{
attron( A_REVERSE );
printw(\"%s\", s );
attroff( A_REVERSE );
refresh();
}
void get_input_text( char *s, int max_len )
{
getnstr( s, max_len );
}
void restore_screen()
{
endwin();
}
//str_main.cpp
#include \"util.h\"
#include \"text_processing.h\"
#include
using namespace std;
/*
Note that grace_open() must be defined in same file
as main(), otherwise the destructor of fstream will
automatically close the opened file as it finds that
its out of scope upon exiting the function.
*/
int grace_open( char *s, fst.
I need to fill-in TODOs in .cpp file and in .h file Could some.pdfforladies
I need to fill-in //TODO\'s in .cpp file and in .h file
Could someone help me at least with few of them to give me an idea how deal with it.
***SinglyLinkedList.cpp
#include
#include
#include \"SinglyLinkedList.h\"
void test_constructor() {
SinglyLinkedList lst = {100, 200, 300, 400, 500};
assert(*lst.at(0) == 100);
assert(*lst.at(1) == 200);
assert(*lst.at(2) == 300);
assert(*lst.at(3) == 400);
assert(*lst.at(4) == 500);
assert(lst.size() == 5);
}
void test_remove() {
SinglyLinkedList lst = {100, 200, 300, 400, 500};
lst.remove(2);
assert(*lst.at(0) == 100);
assert(*lst.at(1) == 200);
assert(*lst.at(2) == 400);
assert(*lst.at(3) == 500);
assert(lst.size() == 4);
}
void test_insert() {
// TODO
}
void test_push_back() {
// TODO
}
void test_push_front() {
// TODO
}
void test_append() {
// TODO
}
void test_sum() {
// TODO
}
int main() {
test_constructor();
test_remove();
test_insert();
test_push_back();
test_push_front();
test_append();
test_sum();
}
***SinglyLinkedList.h
#include
#include
template
class SinglyLinkedList {
// Nested class representing the nodes in the list.
class SinglyLinkedListNode {
public:
// The value stored in this node.
T value;
// The next node in the sequence.
SinglyLinkedListNode *next;
SinglyLinkedListNode(T value) :
value(value), next(nullptr) {}
SinglyLinkedListNode(T value, SinglyLinkedListNode *next) :
value(value), next(next) {}
// Return the size (length) of the linked list.
std::size_t size();
};
SinglyLinkedListNode *head;
SinglyLinkedListNode *tail;
public:
// Constructs a new SinglyLinkedList from an initializer_list of type T[].
// This is mostly for convenience, especially when testing.
SinglyLinkedList(std::initializer_list items) : head(nullptr), tail(nullptr) {
if (items.size() == 0) {
return;
}
// initializer_lists were designed to be used iteratively,
// so thats what we do.
// Can you think of how to write this recursively?
auto it = items.begin();
while (it != items.end()) {
this->push_back(*it++);
}
}
// Return a pointer to the value at the given index.
// If the index is larger than the size of the list,
// return a nullptr.
//
// ASIDE: We will cover exceptions later.
T* at(std::size_t i);
// Pushes a new node onto the back of the list.
void push_back(T value);
// Pushes a new node onto the front of the list.
void push_front(T value);
// Return the size (length) of the linked list.
std::size_t size();
// Remove the specified node from the list.
void remove(std::size_t i);
// Insert the value at the index.
void insert(std::size_t i, T value);
// Append the given list to this one.
void append(SinglyLinkedList list);
};
template
T* SinglyLinkedList::at(std::size_t i) {
// TODO
}
template
void SinglyLinkedList::push_back(T value) {
// TODO
// Make sure that this is a O(1) operation!
}
template
void SinglyLinkedList::push_front(T value) {
// TODO
// Make sure that this is a O(1) operation!
}
template
void SinglyLinkedList::remove(std::size_t i) {
// TODO
// Don\'t forget to not only unlink the node, b.
Write a program that accepts an arithmetic expression of unsigned in.pdfJUSTSTYLISH3B2MOHALI
Write a program that accepts an arithmetic expression of unsigned integers in postfix notation
and builds the arithmetic expression tree that represents that expression. From that tree, the
corresponding fully parenthesized infix expression should be displayed and a file should be
generated that contains the three address format instructions. This topic is discussed in the week
4 reading in module 2, section II-B. The main class should create the GUI shown below:
Pressing the Construct Tree button should cause the tree to be constructed and using that tree, the
corresponding infix expression should be displayed and the three address instruction file should
be generated. The postfix expression input should not be required to have spaces between every
token. Note in the above example that 9+- are not separated by spaces. The above example
should produce the following output file containing the three address instructions:
Add R0 5 9
Sub R1 3
R0 Mul R2 2 3
Div R3 R1 R2
Inheritance should be used to define the arithmetic expression tree. At a minimum, it should
involve three classes: an abstract class for the tree nodes and two derived classes, one for
operand nodes and another for operator nodes. Other classes should be included as needed to
accomplish good object-oriented design. All instance data must be declared as private.
You may assume that the expression is syntactically correct with regard to the order of operators
and operands, but you should check for invalid tokens, such as characters that are not valid
operators or operands such as 2a, which are not valid integers. If an invalid token is detected a
RuntimeException should be thrown and caught by the main class and an appropriate error
message should be displayed. Three Adddress Generator Enter Postfix Expression 359 2 3
Construct Tree Infix Expression ((3-(5 9))/ (2* 3
Solution
#include
#include
#include
#include
#include
struct TREE //Structure to represent a tree
{
char data;
struct TREE *right,*left,*root;
};
typedef TREE tree; /* Stack Using Linked List */
struct Stack //Structure to represent Stack
{
struct TREE *data;
struct Stack *next,*head,*top; //Pointers to next node,head and top
};
typedef struct Stack node;
node *Nw; //Global Variable to represent node
void initialize(node *&n)
{
n = new node;
n -> next = n -> head = n -> top = NULL;
}
void create(node *n)
{
Nw = new node; //Create a new node
Nw -> next = NULL; //Initialize next pointer field
if(n -> head == NULL) //if first node
{
n -> head = Nw; //Initialize head
n -> top = Nw; //Update top
}
}
void push(node *n,tree *ITEM)
{
node *temp = n -> head;
if(n -> head == NULL) //if First Item is Pushed to Stack
{
create(n); //Create a Node
n -> head -> data = ITEM; //Insert Item to head of List
n -> head = Nw;
return; //Exit from Function
}
create(n); //Create a new Node
Nw -> data = ITEM; //Insert Item
while(temp -> next != NULL)
temp = temp -> next; //Go to Last Node
temp -> next = Nw; //Point New node
n -> top = Nw; //Upda.
THE CODE HAS A SEGMENTATION FAULT BUT I CANNOT FIND OUT WHERE. NEED .pdffathimahardwareelect
THE CODE HAS A SEGMENTATION FAULT BUT I CANNOT FIND OUT WHERE. NEED
HELP FIXING THIS CODE?
THIS IS THE PROBLEM
Write a program that allows the user to enter two positive integers and outputs their sum. Sounds
simple? Here\'s the catch: The numbers may be any size! They may be way too large to store in a
single variable. You may not assume any particular maximum number of digits.
HERE IS THE CODE
#include
#include
struct node /* Linked list node*/
{
int data;
struct node* next;
};
struct node *newNode(int data) /* Function to create a new node with giving the data*/
{
struct node *new_node = (struct node *) malloc(sizeof(struct node));
new_node->data = data;
new_node->next = NULL;
return new_node;
}
void push(struct node** head_ref, int new_data) /* Function to insert a node at the beginning of
the Doubly Linked List*/
{
struct node* new_node = newNode(new_data); /*allocate a node*/
new_node->next = (*head_ref); /* link the old list off to the new node*/
(*head_ref) = new_node; /*move the head to point to the new node*/
}
/* Adding the contents of two linked lists and return the head node of resultant list*/
struct node* addTwoLists (struct node* first, struct node* second)
{
struct node* res = NULL; /* res is head node of the resultant list*/
struct node *temp, *prev = NULL;
int carry = 0, sum;
while (first != NULL || second != NULL) /*while both the lists exists*/
{
/* Calculate value of next digit in resultant list.
// The next digit is sum of following things
// (i) Carry
// (ii) Next digit of first list (if there is a next digit)
// (ii) Next digit of second list (if there is a next digit)*/
sum = carry + (first? first->data: 0) + (second? second->data: 0);
carry = (sum >= 10)? 1 : 0; /* update carry for next calulation*/
sum = sum % 10; /*update sum if it is greater than 10*/
temp = newNode(sum); /*Create a new node with sum as data*/
if(res == NULL) /*if this is the first node then set it as head of the resultant list*/
res = temp;
else /* If this is not the first node then connect it to the rest.*/
prev->next = temp;
prev = temp; /* Set prev for next insertion*/
if (first) first = first->next; /* Move first pointers to next node*/
if (second) second = second->next; /*Move second pointer to the next node*/
}
if (carry > 0)
temp->next = newNode(carry);
return res; /* return head of the resultant list*/
}
void printList(struct node *node) /* function to print a linked list*/
{
while(node != NULL)
{
printf(\"%d \", node->data);
node = node->next;
}
printf(\"\ \");
}
int main(void) /* program to test above function*/
{
struct node* res = NULL;
struct node* first = NULL;
struct node* second = NULL;
printf(\"Enter first positive integer: \");
scanf(\"%d\",&first);
printList(first);
printf(\"Enter second positive integer: \");
scanf(\"%d\",&second);
printList(second);
/*Add the two lists and see result*/
res = addTwoLists(first, second);
printf(\"Sum is: %d\");
printList(res);
return 0;
}
Solution
#include
#include
typedef struct Node
{
int da.
The Morse code (see Table 6.10 in book) is a common code that is use.pdfbhim1213
The Morse code (see Table 6.10 in book) is a common code that is used to encode messages
consisted of letters and digits. Each letter consists of a series of dots and dashes; for example, the
code for the letter a is *- and the code for the letter b is -***. Store each letter of the alphabet in a
node of a binary tree of level 5. The root node is at level 1 and stores no letter. The left node at
level 2 stores the letter e (code is *), and the right node stores letter t (code is -). The 4 nodes at
level 3 store the letters with codes (**, *-, -*, --). To build the tree (see Figure 6.38 in book),
read a file in which each line consists of a letter followed by its code. The letters should be
ordered by tree level. To find the position for a letter in the tree, scan the code and branch left for
a dot and branch right for a dash. Encode a message by replacing each letter by its code symbol.
Then decode the message using the Morse code tree. Make sure you use a delimiter symbol
between coded letters.
Implementation Notes: You will need to complete the generic implementation of the BinaryTree
data structure first (see slides). Once it is complete, solve the problem above (note that the book
uses dots and dashes, we will use the asterisk (*) as the dot, hyphen (-) as a dash, and space ( ) as
the delimiter symbol between coded letters). Provide a menu program that asks the user to 1) test
output for all morse code letters with their respective translated alphabet letters (make sure you
are using the binary tree to do the actual translation, output as a nicely formatted table), 2) enter
an input file name to decode morse code and output the translated text to the screen, or 3) enter
in a line of morse code through the console to decode morse code and output the translated text
to the screen
relevenat picture of both the tree diagram and the table of morse code
Solution
JAVA CODE:
import java.io.*;
import java.util.*;
public class MorseCoder implements MorseCodeInterface {
private MorseNode root;
/**
* constructor to build the tree
*/
public MorseCoder() {
root = new MorseNode();
readTreeInfo();
}
/**
* reads in the tree info from the text file (helper method)
*/
private void readTreeInfo() {
Scanner input = null;
try {
input = new Scanner(new File(\"encodings.txt\"));
} catch (FileNotFoundException exception) {
System.out.println(\"File not found!\");
}
while (input.hasNextLine()) {
String data = input.nextLine().trim();
if (data.length() > 0) {
add(data.substring(1).trim(), data.charAt(0));
}
}
input.close();
}
/**
* adds the letter to the tree based on the mcode string (helper method)
* @param mcode the string being fed in
* @param ltr the letter being added at the node
*/
private void add(String mcode, char ltr) {
MorseNode current = root;
String signal = \" \";
for (int i = 0; i < mcode.length(); i++) {
signal = mcode.substring(i, i + 1);
if (signal.equals(\".\")) {
if (current.getLeft() != null) {
current = current.getLeft();
} else {
current.set.
Discuss about Header Node And also write a program for unordered si.pdfeyevision3
Consider rectangle ABCD. If mADF=60°, then what is the mFDC?
a) 60°
b) 30°
c) 90°
d) 120°
e) 45°
f) None of the above
Solution
Given figure ABCD is a rectangle.
Looking into the properties of rectangle,
1) All the angles in a rectangle are right angles i.e. equal to 90 degrees.
2) Opposite sides are parallel and equal.
By the first property stated above,
m(D) = 90 degrees
Angle D can be written as given in the following
m(D) = m(ADF) + m(FDC) = 90
Given m(ADF) = 60
Therefore, 60 + m(FDC) = 90
m(FDC) = 30 degress.
Hence option B) 30 is the required answer..
Similar to Program In C You are required to write an interactive C program that.pdf (20)
Describe the role of soil microbes in the formation and maintenance .pdfamitbagga0808
Describe the role of soil microbes in the formation and maintenance of water-stable soil
aggregates. Can you identify two mechanisms through which soil microbes contribute to the
formation and stabilization of such aggregates?
soild science
Solution
Formation and maintenance ofwater-stable solid aggregates in the soil are important parts of soil
formation and tillage. The microorganisms play a very important role in it. The microbes
normally reside in the soil as a major part of their life cycle. The microbes residing in the soil
perform following function for maintaining soil quality and texture:
1. The microbes survive on soil as a nutrient source. Small microbes such as some bacteria and
fungi absorb nutrients from the soil, digest them in their gut and release the excreta rich in
polysaccharides and polyuronic acids. These polysaccharides are water-stable and thus help in
aggregating small particles of soil and hence bind them.
2. As the microbes gradually complete their life cycle, they die and decay in the soil. As they
decay, the bio-molecules and bio-polymers get assimilated in the soil. Since these microbial bio-
molecules and bio-polymers are rich in water stable compounds,they agglutinate with minute soil
particles to generate water-stable hydrophobic aggregates.
Thus, the two mechanisms can be distinguished as described above as:
1. Release of bio-molecules from microbes
2. Decay and assimilation of microbes in soil
For example: Zygomyceta (vascular arbuscular mycorrhizal fungi) and some bacteria..
Chapter 9Problem P 9-1The narrative and systems flowchart for.pdfamitbagga0808
Chapter 9:
Problem: P 9-1:
The narrative and systems flowchart for the Bridgeport LLC cash
receipts system are included in Exhibit 9.5 and Figure 9.11 (pg. 348),
respectively.
Using Exhibit 9.5 and Figure 9.11, do the following:
a. Prepare a control matrix, including explanations of how each recommended control plan helps
to accomplish? Or would accomplish in
the case of missing plans? Each related control goal. Your choice of
recommended control plans should come from Figure 9.4 (pg. 325)/
Exhibit 9.3 (pp. 329? 330) or Figure 9.6 (pg. 334)/Exhibit 9.4 (pg. 338), as appropriate. Be sure
to tailor the matrix columns to conform to the
specifics of the Bridgeport system. In doing so, assume the following
two effectiveness goals only:
- Timely deposit of checks?
-Compliance with compensating balance agreements with the
depository bank?
Control Goals of the Bridgeport Cash Receipts Process
Control Goals of the Operations Process
Control Goals of the Information Process
Ensure effectiveness of operations:
Ensure efficient employment of resources (people, computers)
Ensure security of resources (cash, accounts receivable master data)
For the remittance advice inputs (i.e., cash receipts), ensure:
For the accounts receivable master data, ensure:
Recommended control plans
A
B
IV
IC
IA
UC
UA
Present Controls
P-1: Turnaround documents
P-2: Endorse checks immediately
P-3: Preformatted screens
P-4: Compare input data with master data
P-5: Programmed edit checks.
P-6: Procedure for rejected inputs
P-7: Manual agreement of RA batch totals
P-8: Manual agreement of deposit batch totals
Missing Controls
M-1: Document design
M-2: Enter cash receipts in the mailroom (enter data close to original source)
M-3: Computer agreement of batch totals
Possible effectiveness goals include the following:
A – Timely deposit of checks
B – Comply with compensating balance agreements with the depository bank
IV = input validity
IC = input completeness
IA = input accuracy
UC = update completeness
UA = update accuracy
Control Goals of the Bridgeport Cash Receipts Process
Control Goals of the Operations Process
Control Goals of the Information Process
Ensure effectiveness of operations:
Ensure efficient employment of resources (people, computers)
Ensure security of resources (cash, accounts receivable master data)
For the remittance advice inputs (i.e., cash receipts), ensure:
For the accounts receivable master data, ensure:
Recommended control plans
A
B
IV
IC
IA
UC
UA
Present Controls
P-1: Turnaround documents
P-2: Endorse checks immediately
P-3: Preformatted screens
P-4: Compare input data with master data
P-5: Programmed edit checks.
P-6: Procedure for rejected inputs
P-7: Manual agreement of RA batch totals
P-8: Manual agreement of deposit batch totals
Missing Controls
M-1: Document design
M-2: Enter cash receipts in the mailroom (enter data close to original source)
M-3: Computer agreement of batch totals
Possible effectiveness goals include the following:
A – Timely deposit.
Compare and contrast the thick and thin filaments.SolutionTher.pdfamitbagga0808
Compare and contrast the thick and thin filaments.
Solution
There are two different types of filaments that extend along the muscle tissues in cylindrical
shapes. Together these two filaments are known as myofibrils.
Thick Filaments:
1. Myosin(a large family of motor protein ) are found to be present in these thick filaments in a
bipolar fashion
2. These filaments can be found in one of the bands of sarcomere (skeletal muscle tissue) called
A-Band (anisotropic band named after its property to be directionally dependent unlike isotropy )
3. These filaments are divided/separated by an M-Line which is made up of myomesin protein
Thin Filaments
1.Unlike thick filaments, thin filaments are made up of 3 types of proteins (actin, tropomyosin,
and troponin) while troponin and tropomyosin are engaged is muscle contraction, actin is
engaged in cell shape and cell adhesion.
2. Thin filaments are present in both A-Band and I-Band (While A-Band is anisotropic due to its
quality of being directionally dependent, I-Band is isotropic band being directionally
independent
3. It is divided by a different proteinaceous non-contractile line called Z-Line.
Anatomy can be studied in many ways. Regional anatomy is the study of.pdfamitbagga0808
Anatomy can be studied in many ways. Regional anatomy is the study of particular areas of the
body, such as the head or leg. Most undergraduate college courses in anatomy and physiology
(and the format of this lab manual) involve systemic anatomy he study of organ systems, such as
the skeletal system and nervous system. Although organ systems are studied separately, it is
important to realize the intimate connections between the systems. If the heart fails to pump
blood as part of the circulatory system, then the lungs do not receive blood for oxygenation and
the intestines do not transfer nutrients to the blood as fuel. The brain and other organs are no
longer capable of functioning, and the result is death. From a clinical standpoint, the failure of
one system has impacts on many other organ systems. There are 11 organ systems that have
functions unique to them. A brief overview of these systems is presented in the following
paragraphs. Reproductive the gonads (testes and ovaries) contain the sex-producing cells of the
body, and the accessory organs, such as the uterus, vagina, penis, and seminal vesicles, play a
part in the transport of the sex cells and the development of the fetus. Urinary the kidneys serve
as filters of the body, and the urinary bladder is a storage organ. The
Solution
The procedure to study the reproductive system of human is follow regional anatomy process
and; to view and study all organs seperately. The male reproductive system consists of series of
oragans. The major organs are testes and scrotal sac which help in the production and storage of
spermatozoa. There are various glands such as seminal vesicle, prostate and vas deferens; they
are responsible for ejaculation of fluids. The final category are useful during copulation; these
are penis, urethra, and cowper\'s gland.
The female reproductive system consists of the following organs; the vaginal area, the uterus and
the ovaries. The female reproductive system recieves the male sex cells (sperms) through the
vaginal area and is transported to the fallopian tube where they meet the female sex cell (ovum).
This event leads to fertilization of the ovum and initiation of development of the fetus..
A red blood cell enters the right atrium from the superior vena cava..pdfamitbagga0808
A red blood cell enters the right atrium from the superior vena cava. In order, list ALL the
structures it passes through to reach the right coronary artery. Be sure to include ALL the
chambers of the heart, and the valves of the heart that it passes through. A red blood cell enters
the celiac trunk from the aorta. In order, list ALL the structures it passes through to reach the
right carotid artery. Be sure to include ALL the chambers of the heart, and the valves of the heart
that it passes through.
Solution
Q.No 1
Heart contains four chambers, two atria and a couple of ventricles. The blood that is definitely
returned to the right atrium is deoxygenated and s passed into the right ventricle to be pumped
through the pulmonary artery to the lungs for reoxygenation and elimination of carbon dioxide.
The left atrium receives newly oxygenated blood through the lungs with the pulmonary veins,
that may be passed throughout the strong left ventricle to be pumped through the aorta to the
various organs of one\'s body.
Superior Vena Cava
The superior vena cava is one of these two main veins bringing de-oxygenated blood from the
entire body to heart. Veins through the head and upper body feed into the superior vena cava,
which empties into the right atrium of the heart.
Inferior Vena Cava
The inferior vena cava is one of these two main veins bringing de-oxygenated blood from the
entire body to heart. Veins through the legs reducing torso feed into the inferior vena cava, which
empties into the right atrium of the heart.
Aorta
The aorta is the main single circulatory around the body. It is around the diameter from your
thumb. This vessel carries oxygen-rich blood from the left ventricle to different parts of one\'s
body.
Pulmonary Artery
The pulmonary artery is the vessel transporting de-oxygenated blood from the right ventricle to
the lungs. Perhaps the most common misconception is all arteries carry oxygen-rich blood. It
really is appropriate to classify arteries as vessels carrying blood away from the heart.
Pulmonary Vein
The pulmonary vein is the vessel transporting oxygen-rich blood through the lungs to the left
atrium. Perhaps the most common misconception is all veins carry de-oxygenated blood. It really
is appropriate to classify veins as vessels carrying blood to heart.
Papillary Muscles
The papillary muscles attach to the reduced percentage of the interior wall of one\'s ventricles.
They connect with the chordae tendineae, which attach to the tricuspid valve in the right
ventricle and the mitral valve around the left ventricle. The contraction of the papillary muscles
closes these valves. When the papillary muscles relax, the valves open.
Chordae Tendineae
The chordae tendineae are tendons linking the papillary muscles to the tricuspid valve in the
right ventricle and the mitral valve around the left ventricle. As the papillary muscles contract
and relax, the chordae tendineae transmit the resulting increase and reduce in tension to
respecti.
You have been hired by Planet Poachers to write a Java console appli.pdfamitbagga0808
You have been hired by Planet Poachers to write a Java console application that reads, converts,
sorts, and writes planet data. Create text file PlanetDataEnglish.txt, paste the following data into
it, and place the file in your project folder.
PlanetDataEnglish.txt
Planet Escape Velocity (miles/s) Mean Temperature (F) Number of Moons
Mercury 2.7 333 0
Venus 6.4 867 0
Earth 7.0 59 1
Mars 3.1 -85 2
Jupiter 37.0 -166 67
Saturn 22.1 -220 62
Uranus 13.2 -320 27
Neptune 14.6 -330 13
Pluto 0.7 -375 5
Create the following methods:
Column Purpose
readTextFile To read the data from file PlanetDataEnglish.txt into four parallel arrays: planets,
escapes, means, and moons.
printArrays To print the unsorted, converted, and sorted data using the appropriate column
headers.
convertArrays To convert the escape velocities from miles/s to km/s, and to convert the mean
temperatures from Fahrenheit to Celsius.
bubbleSortArray To sort the data by planet name in ascending order. Note that when values are
swapped in one array, the same values must be swapped in the other arrays.
writeTextFile To write the data to file PlanetDataMetric.txt in the same layout as the input file.
Sample Output on .txt file
PlanetDataMetric.txt
Planet Escape Velocity (miles/s) Mean Temperature (F) Number of Moons
Earth 11.3 15 1
Jupiter 59.5 -110 67 …
Solution
Following will be program for the planet as requested
//Inclusion of the lib files
Import Java.util.scanner;
import java.io.Filewriter;
import java.io.PrintWriter;
Import java.io.FileNotFoundException;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.File;
Public class Planets // Main method is followed
{
public static void main(String[] args) // main mehtod
{
// variables are declared
scanner keyboard = new Scanner(System.in); // here the keyboard will be connected
Scanner fileIn = null; //file variable are declared
String fileInName = \"PlanetSourceData.txt\";// File name variable is declared
int i=0;
int j=0;
int k =0;
int Usednumber = 10;
String [] Plantets = new String[20];
int [] diameters = new int[15];
double [] leng = newdouble [12];
try
{
fileIn = new Scanner(new FileInputStream(fileInName)); //Scanning of the text file is done
}
Catch(FileNotFoundException e) \\\\catching of the exception
{
System.out.printIn(\"Error:File \'\" +fileInName+ \"\' not found.\"); //gives the error message that
file is not found
System.exit(-1);
}
System.out.println(\"This is templelate from Java keyboard entry\");
// To read the input file this loop is formed
while(fieIn.hasNextLine())
{
Planets[i] = fileIn.next();
diameters[j] = fileIn.nextInt();
lengths[k] = fileIn.nextDouble();
System.out.Printf(\"%-10 %8s %8s %n\" , \"Planets\", \"Diameter(miles)\",\" Hours of the
planest(Length of the planet:);
System.out.printf(\"%-10s %8d %8.1f 5n \", planets[i], diameters[j] , lenths [k]);
}
PrintArray(diameters, numberUsed);
bubbleSortArray(diameters,numberUsed); //finding the miles(escape velocity)
printArray(dua.
An organism that has a normal diploid autosome set with an XXY sex c.pdfamitbagga0808
An organism that has a normal diploid autosome set with an XXY sex chromosome complement.
It would be a
a.
intersex fly, male human being
b.
female fly, female human being
c.
male fly, male human being
d.
male fly, female human being
e.
female fly, male human being
Solution
Option E .
female fly and male human being..
Which level of Orange Book protection is considered mandatory protec.pdfamitbagga0808
Which level of Orange Book protection is considered mandatory protection and is the first level
in which labels are required?
A. B3
B. C2
C. B1
D. A1
Solution
C. The Orange Book rates systems as one of four categories. Category A is verified protection, B
is mandatory protection, C is discretionary protection, and D is minimal protection. B1 is the first
level in which labels are required. Therefore, answers A, B, and D are incorrect.
Why is it an advantage for the epiglottis to fit over the trachea.pdfamitbagga0808
Why is it an advantage for the epiglottis to fit over the trachea?
Solution
Epiglottis is a leaf like , yellow, elastic cartilage forming anterior wall of the laryngeal inlet.
The epiglottis is located on the trachea that is closed during the swallowing of meals which
prevents the aspiration of food , water and other sunstances into the Lungs. Aspiration of food
into Lungs leads to obstruction of trachea is called as choking, and also leads to fibrosis of lung
leads to death of the patient. Hence the epiglottis is fitted in the trachea..
This is Function Class public abstract class Function { .pdfamitbagga0808
//This is Function Class
public abstract class Function {
/**
* Calculates the value f(x) of the function at x
* @param x The x-value at which the function will be evaluated
* @return a double, the value of the function at x
*/
public abstract double fnValue(double x);
/**
* Translates f(x) to the display coordinate system. Note that Java graphics
* places (0,0) in the upper left, and (xmax, ymax) in the lower right of the
* display. A buffer of 5 pixels is kept at top and bottom.
* @param x the value at which f(x) will be evaluated
* @param d the height in pixels of the display
* @param minY the minimum f(x) to be displayed, over the extent of the x\'s
* @param maxY the maximum f(x) to be displayed, over the extent of the x\'s
* @return the value of f(x) translated to the display coordinate system
*/
public double fnValueToPlot(double x, double d, double minY, double maxY) {
double y = fnValue(x);
double yDraw = (d+5)-((y-minY)*(d/(maxY-minY)));
return yDraw;
}
/**
* Determines the display value where y=0
* @param height Height of the Canvas
* @param minY th=0e minimum height of the function within the chosen extents
* @param maxY the maximum height of the function within the chosen extents
* @return the value of y to display corresponding to y
*/
public double originToPlot(double height, double minY, double maxY) {
double yDraw = (height+5)-((0-minY)*(height/(maxY-minY)));
return yDraw;
}
}
//This is GraphManager Class
public class GraphManager implements GraphManagerInterface {
private double xLeft, xRight;
private double yTop = Integer.MIN_VALUE;
private double yBottom = Integer.MAX_VALUE;
private int functionChoice=-999;
Function function1, function2, function3, function4, function5, function6;
/**
* Constructor instantiates the functions specified.
*/
GraphManager() {
function1 = new Function1();
function2 = new Function2();
function3 = new Function3();
}
/**
* getFnValue calculates the value of the function requested by the user, at a specific x value.
* @param fnNum the choice of which function to evaluate
* @param x the value at which to evaluate the function
* @return the value of f(x)
*/
public double getFnValue (int fnNum, double x) {
switch(fnNum) {
case 1: return function1.fnValue(x);
case 2: return function2.fnValue(x);
case 3: return function3.fnValue(x);
default: return 0;
}
}
/**
* Sets the function choice
* @param choice an integer indexing the function desired
*/
public void setFunctionChoice(int choice) {
functionChoice = choice;
}
/**
* Gets the function index previously selected by the user
* @return an index 1-4 corresponding to a function
*/
public int getFunctionChoice() {
return functionChoice;
}
/**
* Gets the actual function instance
* @param choice the index of the function desired
* @return an instance of a sub-class of the Function class
*/
public Function getFunction(int choice) {
switch(choice) {
case 1: return function1;
case 2: return function2;
case 3: return function3;
default: return null;
}
}
/**
* Sets.
What factors are likely to be involved in setting the limit to how lo.pdfamitbagga0808
What factors are likely to be involved in setting the limit to how long an animal migration can
be? In other words, could you predict an animals1 longest possible migration given measures of
physiological performance, morphology etc...? If yes, what would those be?
Solution
Migration is a typical conduct of eukayotic animals.Migration is refinement of complex
connection between inside components, for example, genetics,physiology and conduct and outer
variables weather,habitat condition, sustenance accessibility, predation geology. Migration is
the development of individuals starting with one area then onto the next and broadly connected
with change of perpetual place of habitation. Reasons of Migration are between local and
intraregional differences at full scale level and generally absence of business openings coming
about low expectation for everyday comforts conditions among various financial gatherings at
smaller scale level. There are three segments of populace change. They are mortality, richness
and migration. There are two sorts of movement: interior migration and worldwide movement.
Inner migration is the development of individuals from one place to other place in a given nation.
Universal migration is the development of individuals starting with one nation then onto the next
so as to take up work of set up living arrangement or to increment in expectation for everyday
comforts.
The vital elements which rouse individuals to move can be ordered into five classifications. They
are financial components, statistic variables, socio-social elements, political elements and
incidental elements. (i) Economic Factors Most of the reviews show that migration is basically
roused by financial elements. In creating nations, low agrarian wage, horticultural unemployment
and underemployment are viewed as essential elements pushing the vagrants towards created
zone with more prominent openings for work. Accordingly, all reviews agree that the vast
majority of transients have moved looking for better monetary open doors.
The essential financial variables which inspire migration might be further named \'Push Factors\'
and \'Force Factors\'. The push components are variables that force a man, because of various
reasons, to leave that place and go to some other place. The regular push components are low
efficiency, unemployment and underdevelopment, poor monetary conditions, absence of chances
for headway, fatigue of normal assets and characteristic cataclysms. Presentation of capital
serious techniques for generation into farming part, and automation of specific procedures
diminish work necessity in rustic regions. The non-accessibility of option wellsprings of wage in
country region is additionally essential component for movement. The Pull Factors will be
components which draw in the transients to a zone. Open doors for better business, higher wages,
offices, better working conditions and appealing pleasantries are draw components of a range.
(ii) Demo.
What is alternative splicing What is the difference between mRNA sp.pdfamitbagga0808
What is alternative splicing? What is the difference between mRNA splicing and editing?
Solution
Alternative splicing is a process by which exons or portions of exons or noncoding regions
within a pre-mRNA transcript are differentially joined or skipped, resulting in multiple protein
isoforms being encoded by a single gene
RNA splicing is a process that removes introns and joins exons in a primary transcript. Where as
RNA editing is any process, other than splicing, that results in a change in the sequence of a
RNA
transcript such that it differs from the sequence of
the DNA template.
What are histones and their role in regulating transcription. .pdfamitbagga0808
What are histones and their role in regulating transcription.
What is histone methylation and histone acetylation and how do these effect transcription.
How are genes subdivided?
What are histones and their role in regulating transcription.
What is histone methylation and histone acetylation and how do these effect transcription.
How are genes subdivided?
What is histone methylation and histone acetylation and how do these effect transcription.
How are genes subdivided?
Solution
Histones are alkaline proteins which are found inside the nucleus of eukaryotic cells that
condense and structure the DNA into units called nucleosomes.They function as spools for the
thread like DNA to wrap around and play a role in gene regulation.
2 types of histones
Core histones (H2A, H2B, H3and H4) and linker his tones ( H1 and H5).
Histone methylation (lysine methylation) can either activate or repress gene expression
depending on both the location of the modified lysine and which his tone is the target. For
example, if this occurs in histone H3 at lysine 4, it is linked to gene activation and if it occurs at
lysine 9 it is a marker for gene silencing.
His tone acetylation removes the negative charge from lysine so it can no longer bind to the
DNA phosphate backbone. This weakens the interaction between histones and DNA, resulting in
a more relaxed DNA structure which is more available for DNA transcription. Histone acetyl
transferase (HAT) complexes are recruited by transcription activator proteins, while the repressor
proteins recruit his tone deacetylase (HDAC) complexes. These add and remove acetylations
respectively..
What are the cellular differences between fungi and protistsSol.pdfamitbagga0808
What are the cellular differences between fungi and protists?
Solution
1.Fungi live in aerobic environment to survive, whereas protists live in an anaerobic
environment.
2. protists are single-celled, however fungi are multi-celled.
3.The protista kingdom consists of members which are autotrophic and heterotrophic. The
autotrophs are able to make their own food even as heterotrophs depend on others for food.
Fungi can not be considered autotrophic or heterotrophic, although they extra closely relate to
the heterotrophs. Members of the fungi are saprophytes I.e. consume dead or composing
material..
on the basis of the above data, list the media in order according to.pdfamitbagga0808
on the basis of the above data, list the media in order according to their ability to support the
growth of the bacteria
List the three bacterial species in order of their increasing fastidiosness
Why did the most fastidious organism grow poorly in the chemically defined medium? Date
Section Observations and Results Optical Density Readings Nutrient Broth Glucose Broth 1. On
the basis of the above data, lit the media in order (from best toworst) according to their ability to
support the growth of bacteria. 2. List the three bacterialspeciesinorder of their increasing
fastidiousness. 3. Why did the most fastidious organismgrow poorly in the chemically defined
Lab Re Synthetic Broth
Solution
The media most able to support bacterial growth in decreasing order are:
Yeast extract broth, nutrient broth, inorganic synthetic broth, glucose broth.
The bacteria in increasing order of fastidiousness are:
E. coli, A. faecalis, S. mitis
The most fastidious bacteria grew the slowest as it has a complex nutritional requirement, and as
the chemically defined broth has the least variety of nutrients, a fastidious bacteria will take time
to digest the few compounds and make the molecules necessary for survival..
Prove that is L is regular and h is a homomorphism, then h(L) is.pdfamitbagga0808
Prove that is L is regular and h is a homomorphism, then h(L) is regular.
Prove that is L is regular and h is a homomorphism, then h(L) is regular.
Prove that is L is regular and h is a homomorphism, then h(L) is regular.
Solution
If L is a regular language, and h is a
homomorphism on its alphabet, then
h(L) = {h(w) | w is in L} is also a regular language.
Proof : Let E be a regular expression for L.
Apply h to each symbol in E.
Language of resulting RE is h(L).
Let h(0) = ab; h(1) =
.Let L be the language of regular expression
01* +10*.
Then h(L) is the language of regular expression
ab* +(ab)*. which can be simplified
* = , so ab*=ab
is the identitiy under concetenation .
so E=E=E for any RE E
Thus ab*+(ab)* =ab +(ab)*
=ab+(ab)*
Finall , L(ab) is contained in L(ab)*
so RE for h(L) is (ab)*
so h(L) is regular.
Not sure how to do this case analysis please help me do it!1.Are t.pdfamitbagga0808
Not sure how to do this case analysis please help me do it!
1.Are the regions similar?
2.What would be a good forecasting method to use?
3.Are there more advanced methods that might be considered?
Here is the data
https://docs.google.com/spreadsheets/d/1LYZHLx9f0Av9FJ6NLfULMU61cZPV3voqrVzbJNfV
jKk/edit?usp=sharing
Solution
Most people view the world as consisting of a large number of alternatives. Futures research
evolved as a way of examining the alternative futures and identifying the most probable.
Forecasting is designed to help decision making and planning in the present.
Forecasts empower people because their use implies that we can modify variables now to alter
(or be prepared for) the future. A prediction is an invitation to introduce change into a system.
There are several assumptions about forecasting:
1. There is no way to state what the future will be with complete certainty. Regardless of the
methods that we use there will always be an element of uncertainty until the forecast horizon has
come to pass.
2. There will always be blind spots in forecasts. We cannot, for example, forecast completely
new technologies for which there are no existing paradigms.
3. Providing forecasts to policy-makers will help them formulate social policy. The new social
policy, in turn, will affect the future, thus changing the accuracy of the forecast.
Many scholars have proposed a variety of ways to categorize forecasting methodologies. The
following classification is a modification of the schema developed by Gordon over two decades
ago:
Genius forecasting - This method is based on a combination of intuition, insight, and luck.
Psychics and crystal ball readers are the most extreme case of genius forecasting. Their forecasts
are based exclusively on intuition. Science fiction writers have sometimes described new
technologies with uncanny accuracy.
There are many examples where men and women have been remarkable successful at predicting
the future. There are also many examples of wrong forecasts. The weakness in genius forecasting
is that its impossible to recognize a good forecast until the forecast has come to pass.
Some psychic individuals are capable of producing consistently accurate forecasts. Mainstream
science generally ignores this fact because the implications are simply to difficult to accept. Our
current understanding of reality is not adequate to explain this phenomena.
Trend extrapolation - These methods examine trends and cycles in historical data, and then use
mathematical techniques to extrapolate to the future. The assumption of all these techniques is
that the forces responsible for creating the past, will continue to operate in the future. This is
often a valid assumption when forecasting short term horizons, but it falls short when creating
medium and long term forecasts. The further out we attempt to forecast, the less certain we
become of the forecast.
The stability of the environment is the key factor in determining whether tren.
In each of the following situations, data are obtained by conducting .pdfamitbagga0808
In each of the following situations, data are obtained by conducting a research study. Classify
each Experimental or Correlational. Research Study A researcher is interested in whether
listening to different types of music or no music while taking a test affects test scores. Students
are randomly assigned to one of three groups: The first group takes a test without listening to an
iPod, the second group takes the same test while listening to classical music on an iPod, and the
third group takes the test while listening to rock music on an iPod. The researcher compares the
test scores across the three groups. A psychologist is interested in gender and cognition. She
collects data on a large sample of siblings, recording their gender, birth order, and IQ. A
professor of ophthalmology is interested in developmental precursors of vision disorders. He
collects data from a sample of teenagers on right-eye vision, left-eye vision, and whether the
bedroom light was kept off or on as they slept during the night as babies.
Solution
1) Experimental ( There is intervention- types of music)
2) correlational ( There is No intervention, only collection of data)
3) correlational ( There is No intervention, only collection of data).
i need a summary book report on thw Iwoby richard wheelerSolut.pdfamitbagga0808
i need a summary book report on thw Iwo
by richard wheeler
Solution
As part of my ongoing research on a historical novel I want to write set in the 1930s and 40s, I
bought this book on the Battle of Iwo Jima. My father was there as a radioman and gunner on a
landing craft, and I had known some basic information about the battle, but this book did a good
job of filling in the gaps. Further, Wheeler does a thorough job of including the visceral details
that add both incredible realism and admiration for those who experienced this battle.
A wounded veteran of Iwo Jima himself, Wheeler did comprehensive interviewing as part of the
background research for this book. He also interviewed Japanese survivors and got access to
letters written by notable Japanese soldiers such as General Tadamichi Kuribayashi, the architect
of the defenses on Iwo and commander of forces there. Having the Japanese perspective added
greatly to the telling of the story.
This is not fiction; this was a nonfiction retelling of the story. There was substantial detail in the
recounting of many individual incidents. The only downside of the story was that it was
encyclopedic in approach. Whether it was the chosen approach of the author or his writing style,
the story never got personal. Perhaps if it had gotten too personal, the numerous anecdotes would
have suffered somehow. Unfortunately, I found the writing stiff and formal, more like a textbook
than narrative.
The information and individual incidents were extensive, visceral and incredible. Wheeler writes
in one place of a Marine who suffered injuries from five artillery shells, one after the other, but
remarkable survived them, albeit with major injuries. He also goes into detail as to which units
were involved in which assaults and who took the most damage, include Easy Company’s assault
on Mount Surabachi and the famous hoisting of American colors on that mountain..
18 Alicia climbs into the passenger side of her boyfriend Bos car. .pdfamitbagga0808
18 Alicia climbs into the passenger side of her boyfriend Bo\'s car. In an attempt to impress
Alicia, Bo speeds away from the curb as Alicia\'s head presses against the headrest. What allows
Alicia to sense this linear acceleration? A When thrust backward, the medulla sends signals to
the cortex. B When thrust backward, the cerebellum sends signals to the cortex. C Hair cells in
the cochlea bend with the forward motion. D Hair cells in the vestibular system bend with the
forward motion.
Solution
18. Option D. Hair cells in the vestibular system bend in the forward motion.
Vestibular system (otolithic organs) makes us aware of the balance, acceleration.
23. Option C.think the apple and the potato are the same.
Smell and taste receptors work together to give a sense of the taste of the food.
25. Option B. safe
Infants are hard wired to know that sweet taste is deliciuos and nutritious and bitter means
poison..
How to Create Map Views in the Odoo 17 ERPCeline George
The map views are useful for providing a geographical representation of data. They allow users to visualize and analyze the data in a more intuitive manner.
The Roman Empire A Historical Colossus.pdfkaushalkr1407
The Roman Empire, a vast and enduring power, stands as one of history's most remarkable civilizations, leaving an indelible imprint on the world. It emerged from the Roman Republic, transitioning into an imperial powerhouse under the leadership of Augustus Caesar in 27 BCE. This transformation marked the beginning of an era defined by unprecedented territorial expansion, architectural marvels, and profound cultural influence.
The empire's roots lie in the city of Rome, founded, according to legend, by Romulus in 753 BCE. Over centuries, Rome evolved from a small settlement to a formidable republic, characterized by a complex political system with elected officials and checks on power. However, internal strife, class conflicts, and military ambitions paved the way for the end of the Republic. Julius Caesar’s dictatorship and subsequent assassination in 44 BCE created a power vacuum, leading to a civil war. Octavian, later Augustus, emerged victorious, heralding the Roman Empire’s birth.
Under Augustus, the empire experienced the Pax Romana, a 200-year period of relative peace and stability. Augustus reformed the military, established efficient administrative systems, and initiated grand construction projects. The empire's borders expanded, encompassing territories from Britain to Egypt and from Spain to the Euphrates. Roman legions, renowned for their discipline and engineering prowess, secured and maintained these vast territories, building roads, fortifications, and cities that facilitated control and integration.
The Roman Empire’s society was hierarchical, with a rigid class system. At the top were the patricians, wealthy elites who held significant political power. Below them were the plebeians, free citizens with limited political influence, and the vast numbers of slaves who formed the backbone of the economy. The family unit was central, governed by the paterfamilias, the male head who held absolute authority.
Culturally, the Romans were eclectic, absorbing and adapting elements from the civilizations they encountered, particularly the Greeks. Roman art, literature, and philosophy reflected this synthesis, creating a rich cultural tapestry. Latin, the Roman language, became the lingua franca of the Western world, influencing numerous modern languages.
Roman architecture and engineering achievements were monumental. They perfected the arch, vault, and dome, constructing enduring structures like the Colosseum, Pantheon, and aqueducts. These engineering marvels not only showcased Roman ingenuity but also served practical purposes, from public entertainment to water supply.
Read| The latest issue of The Challenger is here! We are thrilled to announce that our school paper has qualified for the NATIONAL SCHOOLS PRESS CONFERENCE (NSPC) 2024. Thank you for your unwavering support and trust. Dive into the stories that made us stand out!
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdfTechSoup
In this webinar you will learn how your organization can access TechSoup's wide variety of product discount and donation programs. From hardware to software, we'll give you a tour of the tools available to help your nonprofit with productivity, collaboration, financial management, donor tracking, security, and more.
The Indian economy is classified into different sectors to simplify the analysis and understanding of economic activities. For Class 10, it's essential to grasp the sectors of the Indian economy, understand their characteristics, and recognize their importance. This guide will provide detailed notes on the Sectors of the Indian Economy Class 10, using specific long-tail keywords to enhance comprehension.
For more information, visit-www.vavaclasses.com
Unit 8 - Information and Communication Technology (Paper I).pdfThiyagu K
This slides describes the basic concepts of ICT, basics of Email, Emerging Technology and Digital Initiatives in Education. This presentations aligns with the UGC Paper I syllabus.
Unit 8 - Information and Communication Technology (Paper I).pdf
Program In C You are required to write an interactive C program that.pdf
1. Program In C You are required to write an interactive C program that prompts the user for
commands, accepts commands from the keyboard (stdin) and executes those commands. When a
command requires output, it must be written to stdout. The program must continue to accept and
process commands until the user types the end command ourput, it must be writen to stdout. The
program must continue to accept and proces.commands The program deals with linked lists.
Each node of such a list contains a string of length at most 10, a positive integer (i.e., an integer
value 2 1) and a pointer to the next node of the list. For any node, the string and the integer
stored in that node will be referred to as the symbol and count for that node respectively. At all
times, the list must satisfy the following two important properties. 1. The symbols appearing in
the list are all distinct; that is, no two nodes have the same symbol. 2. When the list is scanned
from left to right, the counts must be in non-increasing order. An example of such a linked list is
shown below. Search 4 Maxval4 begin/ Loop head
Solution
/**********************************************/
/****** NAMES ******************** COMMANDS ***/
/* Insert Command : ins str */
/* Delete Command : del str */
/* Forced Delete Command : fde val */
/* Print Statistics Command : pst */
/* Print List Command : prl */
/* Print using Count Range Command: pcr v1 v2 */
/* Print Prefix Command : ppr str */
/* Print Suffix Command : psu str */
/* End Command : end */
/***********************************************/
#include
#include
#include
#define CSIZE 4
#define SSIZE 11
/* Struct for each node in the linked list */
2. struct node
{
int count;
char symbol[SSIZE];
struct node *next;
};
struct node *head;
/* Prototypes for the functions */
void insert(char *);
void delete(char *);
void forced_delete(int value);
void print_stats();
void print_list();
void print_count(int, int);
void print_prefix(char pre[]);
void print_suffix(char suf[]);
void sort_list();
/****************
** Main Method **
****************/
int main(void)
{
int count;
char symbol[SSIZE];
char cmd[CSIZE];
int v1;
int v2;
/* Enter commands */
printf("Command? "); fflush(stdout);
scanf("%s", cmd);
/* Check for command*/
while(strcmp(cmd,"end") != 0)
{
/* check which function to use */
3. if(strcmp(cmd,"ins") == 0) { scanf("%s", symbol); insert(symbol); }
if(strcmp(cmd,"del") == 0) { scanf("%s", symbol); delete(symbol); }
else if(strcmp(cmd,"fde")==0){scanf("%d",&count); forced_delete(count); }
if(strcmp(cmd,"pst") == 0) { print_stats();}
if(strcmp(cmd,"prl") == 0) { print_list(); }
if(strcmp(cmd,"pcr") == 0) { scanf("%d %d",&v1,&v2); print_count(v1,v2); }
if(strcmp(cmd,"ppr") == 0) { scanf("%s", symbol); print_prefix(symbol);}
if(strcmp(cmd,"psu") == 0) { scanf("%s", symbol); print_suffix(symbol);}
printf("Command? "); fflush(stdout);
scanf("%s", cmd);
}// End of While Loop
return 0;
}// End of main method
/***************************
****** Insert Method *******
***************************/
void insert(char *sym)
{
/* Set current node to head, create new new node, and a boolean */
struct node *cur_node = head;
struct node *new_node;
int in_list = 0;
/* If list is empty, then insert in head */
if(cur_node == NULL)
{
// create memory for head, also test if head equal to NULL
head = (struct node *) malloc(sizeof(struct node));
if(head == NULL)
{
printf("Node allocation failed. "); fflush(stdout);
exit(1);
}
/* insert sym inside head->symbol and change count to one */
strncpy(head->symbol, sym, SSIZE);
4. head->count = 1;
head->next = NULL;
}
/* do this part if list is not empty */
else
{
// Insert inside of list
// Check if sym is in list
// Loop though all list
while(cur_node != NULL)
{
// if list is in middle add one count
if(strcmp(sym, cur_node->symbol) == 0)
{
cur_node->count++;
in_list++;
/***** Sort Method *****/
sort_list();
}
//cur_node is bottom of the list right now
cur_node = cur_node->next;
}// End of while loop
/* Do this part if you want to insert in end of list */
if(in_list == 0)
{
// put cur_node at top of the list
cur_node = head;
//insert at end of list
//go at at end of list and put it in cur_node
while(cur_node->next != NULL)
{
//cur_node is at bottom right now
cur_node = cur_node->next;
}
5. /* Create new memory and test if new_node is NULL */
new_node = (struct node *) malloc(sizeof(struct node));
if(new_node == NULL)
{
printf("Node allocation failed. "); fflush(stdout);
exit(1);
}
//link cur_node with new_node and insert inside new_node
cur_node->next = new_node;
strncpy(new_node->symbol,sym,SSIZE);
new_node->count = 1;
new_node->next = NULL;
}
}
}// End of insert method
/*******************************
******** Delete Method *********
*******************************/
void delete(char *sym)
{
struct node *cur_node = head;
struct node *to_delete;
/* Do this if list is empty */
if(cur_node == NULL)
{
printf("List is empty. "); fflush(stdout);
}
/* Do this is list is not empty */
else
{
/* del or minus head node*/
if(strcmp(sym, head->symbol) == 0)
{
if(head->count > 1)
6. {
head->count--;
/**** Sort Method ***/
}
//if cur_node equal one than remove it
else if(cur_node->count == 1)
{
to_delete = head;
head = cur_node->next;
free(to_delete);
to_delete = NULL;
}
}
//check rest of the list
while(cur_node != NULL && cur_node->next != NULL)
{
//If symbol is inside the list
if(strcmp(sym, cur_node->next->symbol) == 0)
{
// if symbol has more than one count
if(cur_node->next->count > 1)
{
cur_node->next->count--;
/******* Sort Method ********/
}
//if symbol has one count than del it
else if(cur_node->next->count == 1)
{
to_delete = cur_node->next;
cur_node->next = cur_node->next->next;
free(to_delete);
to_delete = NULL;
}
}
cur_node = cur_node->next;
}//End of while loop
7. sort_list();
}
}//End of delete method
/**********************
**Forced Delete Method*
***********************/
void forced_delete(int value)
{
//Set the struct node cur_node equal to the head
struct node *cur_node = head;
//If the current node is null return to cmd prompt
if(cur_node==NULL)
return;
//if the the head.next value is null set the head
//equal to null as well
if((head->next==NULL))
head = NULL;
//Else if the given count value of the head is less
//than the value stated set the head equal to null
else if(head-> count <= value)
head = NULL;
//Else if the nodes after the head count are less
//than the given value set the current.next value
//equal to null and traverse through the rest of the list
else
while(cur_node!=NULL){
if(cur_node-> next-> count <= value)
cur_node-> next = NULL;
cur_node = cur_node->next;
}
}
/**********************
******Prefix Method****
***********************/
8. void print_prefix(char pre[SSIZE]){
//Variables declared for the total size of the string.
//Num used as a boolean like value where 0 is false and 1 is true.
//I declared for use in the for loop
int i, size, num;
struct node *cur_node = head;
size = strlen(pre);
//If the head is null return that the list is empty
if(head == NULL)
printf("Empty!. ");
else
{
//While the head is not null traverse
while(cur_node != NULL)
{
// for loop to compare the full string to the string held in the array
// so it can determine if the string is held in the array value
// return 0 for false and 1 for true;
for(i = 0; i < size; i++)
{
if(cur_node->symbol[i] != pre[i]){
num = 0;
break;
}else
num = 1;
}
//If num equals 1(true) print the prefix values of the given string
//and it's integer value.
//update to the next node;
if(num==1)
printf("%s %i ", cur_node->symbol,
cur_node->count);fflush(stdout);
cur_node = cur_node->next;
}
9. }
}
/**********************
******Suffix Method****
***********************/
void print_suffix(char suf[SSIZE]){
//Variables declard for the size of string,
//a boolean type variable, curr to keep track of
//the current string value and suf for the given suffix value
int i, x , curr, size, num;
struct node *cur_node = head;
num = 0;
//Find the size of the given suffix
size = strlen(suf);
//If the head is equal to null the list is empty
if(head == NULL)
printf("Empty! ");
else
{
//While the current node is not null, traverse.
while(cur_node != NULL)
{
x =1;
curr = strlen(cur_node->symbol);
//Loop through the given string size, if the current
//string -1 and the given i value is equal to the suf string
//" " " " return true and get the suffix
for(i = 0; i < size; i++)
{
if(cur_node->symbol[curr - x - i] == suf[size - x - i])
num = 1;
else
10. {
num = 0;
break;
}
}
//If num equals 1(true) print the suffix values of the given string
//and it's integer value.
//update to the next node;
if(num==1)
printf("%s %i ", cur_node->symbol,
cur_node->count);fflush(stdout);
cur_node = cur_node->next;
}
}
}
/**********************
******Print Stats****
***********************/
void print_stats()
{
//Variables declared to find the maximum, minimum, size
// total number and the average
//Set a struct node *cur_node = to the head of the list
int max = 0, min = 0; int size = 0;
double num = 0,avg = 0;
struct node *cur_node = head;
// If the current node is null return all values of 0
if(cur_node==NULL){
printf("Number of nodes: %d ",size);fflush(stdout);
printf("Maximum: %d ",max);fflush(stdout);
printf("Minimum: %d ",min);fflush(stdout);
printf("Average: %d ",avg);fflush(stdout);
return;
}else
11. //Increment size as we traverse the Linked List Nodes
//Number is added to the ammount of cur_node->count for a total number
//Increment to the next node of current
min = head->count;
while(cur_node!=NULL){
size++;
if(min>=cur_node->count)
min = cur_node->count;
num += cur_node->count;
cur_node = cur_node->next;
}
//Calculate the average and set the max = to head->count
//which returns the maximum value
avg = num/size;
max =head->count;
printf("Number of nodes: %d ",size);fflush(stdout);
printf("Maximum: %d ", max);fflush(stdout);
printf("Minimum: %d ",min);fflush(stdout);
printf("Average: %.2f ", avg);fflush(stdout);
}
/**********************
** Print List Method **
***********************/
void print_list()
{
struct node *cur_node = head;
if(cur_node == NULL)
{
printf("The list is empty. ");fflush(stdout);
fflush(stdout);
}
else
{
while(cur_node != NULL)
{
12. printf(" %s %d ", cur_node->symbol, cur_node->count);fflush(stdout);
fflush(stdout);
cur_node = cur_node->next;
}//end of while loop
printf(" "); fflush(stdout);fflush(stdout);
}
}//end of print list method
/***********************
** Print Count Method **
***********************/
void print_count(int x1, int x2)
{
struct node *cur_node = head;
//print this is list is empty
if(cur_node == NULL)
{
printf("The list is empty. "); fflush(stdout);
printf(" ");
}
//print range list
else
{
//loop through list
while(cur_node != NULL)
{
//if its between range than print it
if ((cur_node->count >= x1) && (cur_node->count <= x2))
{
printf(" %s %d ", cur_node->symbol, cur_node->count);
fflush(stdout);
}
cur_node = cur_node->next;
}// End of While Loop
printf(" "); fflush(stdout);
}
13. }//End of Print Count Method
/***********************
****** Sort Method *****
***********************/
void sort_list()
{
struct node *cur_node, *temp;
int loop =1;
while(loop==1)
{
temp = cur_node = head;
loop = 0;
while(cur_node->next != NULL)
{
//case where the next node has a higher count that the cur_node
//the nodes will be swapped around to ensure descending order
if(cur_node->next->count > cur_node->count)
{ // mark that the nodes have been swapped
loop = 1;
//If the cur_node is equal to the head of the list
if(cur_node == head)
{
//The current node is equal to the current.next value
//Set the next temp value equal to next current value
//Store the next current value in the temp variable
//The head is equal to the temp variable and is the current node
cur_node = cur_node->next;
temp->next = cur_node->next;
cur_node->next = temp;
head = temp = cur_node;
//Swapping from other positions in the list
14. //The next temp value is equal to the next current value
//The next current value equals the next value of the current.next
//the current node is equal to the next temp node value
}else{
temp->next = cur_node->next;
cur_node->next = cur_node->next->next;
temp->next->next = cur_node;
cur_node = temp->next;
}
}
//If we need to move the temp node value
//and it doesn't equal the current node..
//The temp value is equal to the next temp value
//Finally update the list to keep going
if(temp != cur_node)
temp = temp->next;
cur_node = cur_node->next;
}
}
}