homework

Finding the "Nth node from the end" of a linked list.

This seems to be returning the correct answer, but I'm not sure if this is really the best way to go about things. It seems like I'm visiting the first n nodes too many times. Any suggestions? Note that I have to do this with a singly linked list. Node *findNodeFromLast( Node *head, int n ) { Node *currentNode; Node *behindCu...

What is the Python code to split up a string so that it prints out normally in an 80-character window without wrapping?

When I run my program (which decrypts a paragraph from a certain document), I have: W E T H E P E O P L E O F T H E U N I T E D S T A T E S I N O R D E R T O F O R M A M O R E P E R F E C T U N I O N E S T A B L I S H J U S T I C E I N S U R E D O M E S T I C T R A N Q U I L I T Y P R O V I D E F O R T H E C O M M O N D E F E N S E P R ...

Reversing a string in C

I know this has been asked thousands of times but I just can't find the error in my code. Could someone kindly point out what I'm doing wrong? #include <stdlib.h> #include <string.h> void reverseString(char *myString){ char temp; int len = strlen(myString); char *left = myString; // char *right = &myString[len-1]; ...

Another algorithm problem...

I am given N numbers and for them apply M rules about their order. The rules are represented in a pairs of indexes and every pair (A, B) is telling that the number with index A (A-th number) must be AFTER the B-th number - it doesn't have to be next to him. Ex: N = 4 1 2 3 4 M = 2 3 2 3 1 Output: 1234, 4213, 4123, 2134,...

What is segmentation fault?

What is segmentation fault? Is it different in C and C++? How are segmentation fault and dangling pointer related? ...

Having minor problems with homework involving C bubble sort

It does not work. #include<stdio.h> void bubble_sort(int m, int a[100000]); void main() { int a[100000], i, m; FILE * be; be=fopen("be.txt","r"); // IMPORTANT! i pressed enter after last number in be.txt!!! for (i=0; !(feof(be)); ++i) fscanf(be,"%i", a+i); m=i-1; bubble_sort(m ,a); fclose(be); } void bubble_sort(int m, in...

Position of elements in vector

I have several elements in a vector type that are read from cin and then i perfrom some calculations on the vector and it's order of elements gets changed. The problem is that I need to print the positions of the vector elements after the calculations. I don't know how to explain this well that's why i'll give an example: 10 1 100 1000 ...

String array in C++ not working properly?

I'm working on a program for class that takes in a number from 0 to 9999, and spits out the word value (ie 13 would be spit out as "thirteen", etc) And I'm having a pain with the array for some reason. Here is the class so far: #include<iostream> #include<string> using namespace std; class Numbers { private: int number;...

System.AccessViolationException while initializing an array.

void BinaryTree::InitializeFromFile(string Filename){ ifstream inFile; treenode* Freq[256]; inFile.open(Filename.c_str(), fstream::binary); if(inFile.fail()){ cout<<"Error in opening file "<<Filename; return; } for(int i=0;i<=255;i++){ Freq[i]->weight=0; Freq[i]->data = '0'+i; Freq[i]->LChild = NULL; Freq[i]->RChild=NU...

How to convert integer to char without C library?

In a c programming exercise I am asked to convert an int to char without using the C library. Any idea how to go about it? edit: what I mean by int is the built in C/C++ type Thanks. ...

Help with creating a private method

I am working on a project and have the following psuedocode: // create a private method, getIntValDialog, that returns an integer value and accepts // two string values as arguments // declare and initialize a string variable, sValue, to an empty string // Accept input to sValue from a Input Dialog using smessage, stitle, and a ...

How could I do frequency analysis on a string without using a switch.

I am working a school project to implement a Huffman code on text. The first part of course requires a frequency analysis on the text. Is there a better way aside from a giant switch and an array of counters to do it? ie: int[] counters for(int i = 0; i <inString.length(); i++) { switch(inString[i]) case 'A': counters[0]++; ...

Entry lvl. COBOL Control Breaks

I'm working in COBOL with a double control break to print a hospital record. The input is one record per line, with, hospital info first, then patient info. There are multiple records per hospital, and multiple services per patient. The idea is, using a double control break, to print one hospital name, then all the patients from that ho...

How do I create a Foreign Key?

Hi I am working on my assignment. It has 8 tables. Each table has a primary key. What do i do to generate a foreign key to a table? My reason for asking is that when I generate a primary key, a key symbol appears on the left. What do i do to make something a foreign key? ...

c program for the reverse the digits

I am looking for the c program for reverse the digits like ...... if i enter 123456 then the result would be .... 654321 plz any one help... ...

Random number generator in C# - unique values

I'm busy in C# with coding an array. I can fill it up with random generators but now is my question how do i do this but so that i can check if the value is already in the array and if so generate an new value Extra info: Max value : 100 Number of elements : 100 IMPORTANT PLZ WORK FURTHER ON MY IDEA my idea public void FillArray(in...

Find a number in an array

I came up with 3 algorithms to attempt the above problem, but I am not sure which one is the best in terms of running time. I'm listing my ideas for the algorithms below and could really use some help to figure out the most efficient algorithm for this. Algo-1 I used selection sort and stopped it once the numbers are sorted. Algo-2 ...

Converting JSON to XML in Perl

Hi foks, my task is to convert JSON file into XML file in Perl. It is forbidden use automatic tools like XML2JSON, so I need to parse JSON in Perl variables and then, store it in XML file. Can you give me some examples how to use JSON:XS and XML:Simple to complete my task? Thanks a lot ...

Understanding how to run a servlet in Eclipse

I'm writing a simple flight reservation application for one of my homeworks. My flight reservation web site has a login, registration, flight search, result display and confirmation JSP pages. I want to invoke servlets when the user attempts to perform an action, for example: The user goes to login.jsp and clicks the Login button, t...

[PHP] How to redirect to a different page and save state information as well?

I am in a web scripting class and our teacher is very strict on the guidelines of the assignment, as he has scripts that grade our work. With that being said we are allowed to use only two forms for our assignment, one for logging in (form 1) and one for submitting data to be entered into a database (form 2). My instructions say: A us...