Hello there guys! I must implement a linked list in assembly (using MIPS). We're supposed to dynamically allocate memory for the nodes. This is what I am asked to do: Write a program in assembly (MIPS) that implements a link-list. The client can choose among the following options. So the program should include: 1. Insertion. Inserting new nodes at the correct spot keeping the list sorted in ascending order. 2. Deletion. Deleting a node, while still keeping the list in ascending order. 3. Printing in ascending order. Printing each node of the list from the first till the last one. …

Member Avatar
Member Avatar
+0 forum 3

Below is my code: #include <stdio.h> #include <stdlib.h> #include <string.h> #include <iostream> using namespace std; ///////////////////////////////////////////////////////////////////////// /* // struct Edge // Represent one edge in the graph. Fields contain // two vertex numbers and a weight. */ struct Edge { int vertex_1, vertex_2, weight; }; //////////////////////////////////////////////////////////////////////// /* // struct Graph // Represents a weighted graph. Fields contain the # of vertices, // edges,an array of edges, along with it's physical size. */ struct Graph { // V-> Number of vertices, E-> Number of edges int V, E; // graph is represented as an array of edges. Since the graph is …

Member Avatar
Member Avatar
+0 forum 6

I'm trying to write a program that has a user input student names, their ages, their GPAs, and their graduations dates (i.e. 'F13', F for Fall, S for Spring, then the last two digits of the year). This information goes into a linked list, then the user can search a name or part of a name to find students and display their information. #include <iostream> #include <cstring> using namespace std; const char NAME_SIZE = 50; struct StudentInfo { char studentName[NAME_SIZE]; int age; double gpa; char graduationSemester[4]; StudentInfo *next; }; void displayStudentNames(StudentInfo *top); void displayStudentInfo(StudentInfo *top); int main(){ StudentInfo *top = …

Member Avatar
Member Avatar
+0 forum 2

So I have writen a program that takes a linkedlist and shuffles it randomly using mergesort algorithm. The problam I'm having now is that the original list loses elements after the shuffle, and after som checking with some outputs it seems that it always one of the extra lists who have elements still left inside them. This is an assignment and here is the task: >Assume you have as input ia singly-linked list containing N >items (an instance of a LinkedList class in Java). You should rearrange the items in the >LinkedList uniformly at random. Your algorithm should consume a …

Member Avatar
Member Avatar
+0 forum 2

Okay. This weeks 'problem' is that I need to simulate a game. I have to make two singly linked lists which will contain a name of player, his attack (double/float) number and his defence number and so on for as many players as the user inputs. The point of the game is to try to break the other 'chain'. You do that by running into 'enemies' chain and trying to break it, you break it if your attack is greater then defence of two players that you are trying to separete. If you separate them you can pick one of …

Member Avatar
Member Avatar
+0 forum 8

This code allows you to create a linked list and reverse it recursively.

Member Avatar
Member Avatar
+0 forum 10

I am implementing Priority QUE as a doubly linked list. My structs: typedef int kintyr; typedef struct qElem { struct qElem *prv; kintyr *dat; int *priority; }qElem; typedef struct que { qElem *fr,*bk; int cnt; }que; And this is my functions to create empty PQ, and to insert elements: que *qNew() { que *q = malloc(sizeof(*q)); if (q==NULL) return NULL; q->fr = NULL; q->bk = NULL; q->cnt = 0; qFault = 0; return q; } que *qEnq(que *q, kintyr *x, int *prrt) { que *zn=q; qFault = 0; if (q == NULL) { qFault = 1; return q; } if …

Member Avatar
Member Avatar
+0 forum 2

So here's my problem I have inner structure inside of client. How can I know while reading from txt file that I'm reading item data or client data for my list? struct item { char item_name[30]; char item_state[30]; float item_price; char item_status[30]; float item_price_if_not; struct item *next; }; struct client { char client_name[30]; char client_last_name[30]; struct item *item_data; struct client *next; }; void savetxt(struct client *head) { FILE *f; f = fopen("data.txt","w"); if(f == NULL) { printf("error"); } struct item *CurrentItem = head->item_data; while(head != NULL) { fprintf(f,"%s %s\n",head->client_name,head->client_last_name); while(CurrentItem != NULL) { fprintf(f,"%s %s %f %s %f ",CurrentItem->item_name,CurrentItem->item_state,CurrentItem->item_price,CurrentItem->item_status,CurrentItem->item_price_if_not); CurrentItem …

Member Avatar
Member Avatar
+0 forum 18

A complete C implementation of Linked List...tested on Linux GCC

Member Avatar
Member Avatar
+0 forum 5

I'm trying to make make project for my programming class. All that's left is deleting elements and editing elements. Basicaly my question is how would I do it for my inner list? Or how would I delete single client from list? Would I first have to free the client's inner list if so how should I proceed to do so? #include <stdlib.h> #include <time.h> #include <string.h> #include <stdio.h> struct date { int day; int month; int year; struct date* next; }; struct item { char item_name[30]; /* char item_state[30]; double item_price; char item_status[30]; double item_price_if_not; struct date *issue_date;*/ struct item …

Member Avatar
Member Avatar
+0 forum 10

Im writing project for my programming lessons and right now got some problems with output from function AddItemToClient, basicaly its mainly with date, in first node its correct one but after this its just random. Could someone explain what I'm doing wrong here? #include <stdlib.h> #include <time.h> #include <string.h> #include <stdio.h> struct date { int day; int month; int year; struct date* next; }; struct item { char item_name[30]; char item_state[30]; double item_price; char item_status[30]; double item_price_if_not; struct date *issue_date; struct item *next; }; struct client { char client_name[30]; char client_last_name[30]; struct item *item_data; struct client *next; }; //ADD CLIENT// …

Member Avatar
Member Avatar
+0 forum 2

i need c++ code for simple linked list to implement algorith and data structure 1.create_node_and add to list 2.frst node delete 3.last node delete 4.delete node between first and last node 5. displaye the value of node in revese order 6. searching 7.exist

Member Avatar
Member Avatar
+0 forum 2

Hi I've tried the code below to merge 2 linked list which f1 and f2 are the first nodes in the initial lists and the "first" is the first node in the result list. But it doesn't work! [CODE] node *merge(node *first,node *f1, node *f2,int n1,int n2){ int n=n1+n2; while(n-- > 0){ if(n1-- > 0)first=insert(first,f1->info); if(n2-- > 0)first=insert(first,f2->info); } return first; }[/CODE] Which insert is the following function that construc a list: [CODE] node *insert(node *first, int x){ if(first==NULL){ first=new node; first->info=x; first->next=NULL; } else{ node *Temp=first; while(Temp->next!=NULL) Temp=Temp->next; Temp->next=new node; Temp=Temp->next; Temp->info=x; Temp->next=NULL; } return first; } [/CODE] Looking …

Member Avatar
Member Avatar
+0 forum 6

How to display odd and even numbers from a queue link list? hello everyone i really need some help right now on this program. what this program is supposed to do is copy 11 22 44 77 33 99 66 into a linked list that behaves like a queue. the program should display the queue, display the odd numbers, display the even numbers. display queue should look like this 11 22 44 77 33 99 66 display odd numbers should look like this 11 77 33 99 display even numbers should look like this 22 44 66 so far i …

Member Avatar
Member Avatar
+0 forum 3

So, I'm using allegro game programming library. Before I move on to bigger and better things I wnat to get a handle on pointers. Specifically with things like structs, linked lists and maybe binary trees in the future. I posted a program that uses a linked list to keep tracks of a variable number of objects on the screen. GDB tells me it fails in the main also, the new style of posting is kinda buggy, for example I can move the cursor past the program code. gdb: Program received signal EXC_BAD_ACCESS, Could not access memory. Reason: KERN_INVALID_ADDRESS at address: …

Member Avatar
Member Avatar
+0 forum 3

Hi guys, I'm trying to read data from an excel "csv" file and save it in a list. the problem is that I want to have a copy of this list named "list1" that will not change during the manipulations and claculations, because when I copied the contents of "list1" to "list2", The content of list2 changed through the program. Can anybody help me on this? [CODE] class FileInfo { public: int a; float b; int c; int d; int e; int f; }; // create lists list<FileInfo*>list1; list<FileInfo*>list2; //read from excel file void FileInput() { //DownloadList_test ifstream file ("test.csv"); …

Member Avatar
Member Avatar
+0 forum 2

Hi all. I am trying to build a Binary Linked Trie but fail in basic pointer operations.Following code can be built but in debug or run mode, it breaks and outputs the error. [ICODE]typedef struct node { char ch; node *next; }; struct node *root = NULL; void add(struct node *leaf, char ch) { leaf = new node; leaf->ch = ch; leaf->next = NULL; } void read() { while(root->next != NULL) cout << root->ch; } int _tmain(int argc, _TCHAR* argv[]) { struct node *conductor; add(root, 'a'); conductor->ch = 'l'; conductor->next = NULL; root->next = conductor; read(); return 0; }[/ICODE] The …

Member Avatar
Member Avatar
+0 forum 3

I have a simple query, I am using code for "QUEUE IMPLEMENTATION USING SINGLE LINKED LIST" [url]http://ds4beginners.wordpress.com/2006/12/17/queue-implementation-using-single-linked-list/[/url] for my program but having an issue if you pleas help me. [CODE]public class queue { gcroot<message^> msg; queue* next; public: queue(); queue* enqueue(queue*,message^); queue* dequeue(queue*); void queue_display(queue*); void setbinding(String^); String^ getbinding(void); }object, *head=nullptr, *tail=nullptr;[/CODE] the rest of queue functions are same as in the link . In the main function I have defined these queues.when I tried to insert element is "weather" queue and display it shows the same element in all the queues declared. Can you help me why this happening. …

Member Avatar
Member Avatar
+0 forum 12

I have a file(myfile.txt) with the following lines, the records are semicolon delimited [I]Bon Jovi;Living + 2;EP;A+ Metal Maze;Aliotta Haynes Music;LP;B- Shore Brothers, The;Wipe my door, check;LP;C+ Bulman, Dane & Greg;Dane & Greg Bulman;LP;C- Calbert, Herb & The Mexico Brass;Rise;LP;A´[/I] . . . I want to write a c program which will read the file and display in the following manners sorted by [B]RATINGS[/B]. The program will display [B]10 rows at a time[/B] on the screen. ARTIST------------------ALBUM--------------------TYPE------------RATING Bon Jovi----------------Living + 2----------------EP---------------A+ Metal Maze--------------Aliotta Haynes Music------LP---------------B- Shore Brothers, The-----Wipe my door, check-------LP---------------C+ Bulman, Dane & Greg-----Dane & Greg Bulman--------LP---------------C- Herb & …

Member Avatar
Member Avatar
+0 forum 3

I need to know how to create methods to compare two sets of singly linked lists. The only problem is that I can't put a linkedlist inside the method parameters. Please help [CODE]import java.util.*; public class SLinkedList { protected Node head; // head node of the list protected Node tail; protected int size; // number of nodes in the list /** Default constructor that creates an empty list */ public SLinkedList() { head = new Node(null, null); // create a dummy head size = 0; } public boolean(SLinkedList obj){//tells me identifier is expected return true; } [/CODE]

Member Avatar
Member Avatar
+0 forum 2

Hello I am a new to C++ and have some questions. I have two classes called Point and Square like this: [CODE] class Point { int x, y; public: int getx() const { return x; } int gety() const { return y; } Point(int a, int b) { x = a; y = b; } }; class Square { public: int x, y, length, width; SquareSpec(){return x, y, length, width;} Square(Point, int, int); }; Square::Square(Point A, int lngt, int wdth){ length = lngt; width = wdth; x = A.getx(); y = A.gety(); } [/CODE] Now the thing is that somehow …

Member Avatar
Member Avatar
+0 forum 14

See I probably have the littlest knowledge on working with Linked Lists and I was thinking of creating a program that will accept three numbers which will be arranged on the list. However, I need to display the numbers everytime I input them, which I don't know how. My goal is to have this: [CODE]Give a number: 2 Display List: 2 Give a number: 3 Display List: 2 3 Give a number: 1 Display List: 1 2 3[/CODE] I'm not actually familiar with how linked lists work so far so any explanation that would give light to this concept is …

Member Avatar
Member Avatar
+0 forum 2

hello all! i am working on a bank account type program where the user can add accounts delete accounts make deposits and so on. i have most of the code working but i am getting an error and i cant figure out whats wrong. if someone could steer me in the right direction on how i could fix it that would greatly appreciated. the error im getting is: C:\Users\kevin jack\Desktop\hume\prog1>g++ -o prog1.exe acctListMain.cpp acctListMain.cpp: In function `int main()': acctListMain.cpp:69: error: expected primary-expression before '.' token acctListMain.cpp file: [CODE]/********************************************** * Prog 1 Kevin Jack * * **********************************************/ #include <iostream> #include <iomanip> …

Member Avatar
Member Avatar
+0 forum 1

I have been having trouble developing a function that frees all of the memory associated with structs of a linked list. Im not asking for a clear cut answer, just an idea or a function that can aid. F.Y.I. the linked list contains a head struct and a tail struct to identify the Here's some code that might spark some thought: [CODE]void deleteAllStructs(void){ struct structTypeName listingPtr; do{ for(listingPtr=gHead;listingPtr->next!=NULL;listingPtr=listingPtr->next) ; listingPtr = NULL; while(gHead!=NULL); }[/CODE]

Member Avatar
Member Avatar
+0 forum 6

Hi all, I'm having a problem here!! I've attended a lecture on Implementation of stacks in c++ using arrays and it wasn't really hard to understand, but now I'm supposed to know how to Implement a stack using linked list, that's the problem. help please?:confused:

Member Avatar
Member Avatar
+0 forum 2

The Question is : Three stacks can be used to sort a list of numbers. Assuming stack in holds the input list of numbers, stack out is to hold the output list after sorting the numbers and temp is used during the sorting process. The sorting algorithm follows. 1 set up stack in and print it 2 while stack in is not empty repeat 2.1 max = in.pop 2.2 while there are still element in stack in repeat 2.2.1 value = in.pop 2.2.2 if value > max 2.2.2.1 temp.push(max) 2.2.2.2 max = value 2.2.3 else 2.2.3.1 temp.push(value) 2.3 in = …

Member Avatar
Member Avatar
+0 forum 1

I have this assignment to do. Its been about a year since I messed with c++ and I've been refreshing my brain on the subject. The assignment is this : Your assignment is to write a program for a computer dating service. Each client gives you his or her name, phone number, and a list of interests. It is your job to maintain lists of men and women using the service and to match up the compatible couples. You will find more details about the assignment, including the inputs, outputs, and deliverables in the course environment. Input Data about current …

Member Avatar
Member Avatar
+0 forum 10

I am implementing Selection sort in doubly - linked list. I have to sort list by surnames by finding smallest element and inserting it into beginning of the list But there are some troubles when I run my program I have NIL exception in Sort Method in while loop. Help will be appreciated. Thanks. It's whole app so you can compile it and run. [CODE]public class LinkedList { public Node first; public Node last; public LinkedList() { first = null; last = null; } public void addFirst(Student student) { Node f = first; Node newNode = new Node(student); first = …

Member Avatar
Member Avatar
+0 forum 2

I am currently working on a project where we must read in a file and then print it back type justified. There must also be a specific number of characters per line based upon user Input with the extra characters being distributed spaces. I am reading in each character from the file storing them individually in an array and then placing the whole word into the linked list(I believe). I am not very experienced with C/C++ so I am not sure I am doing this correctly. I have printed the strings which I believe are being fed into the list …

Member Avatar
Member Avatar
+0 forum 1

Hi, I am trying to work on creating a linked list of player in a game, but I have not written code in a while and have no idea what I am doing wrong, can you please help with suggestion of what I did wrong or idea of how can I improve my code... Thanks This is the h.file for my main [CODE] #pragma once #include <cstdlib> #include <sstream> #include <string> #include <windows.h> using namespace std; template <typename T> class CNode { private: CNode<T>* m_pNext; T m_value; public: CNode(T value); virtual ~CNode(); T& Value(); CNode<T>* getNext(); void setNext(CNode<T>* address); string …

Member Avatar
Member Avatar
+0 forum 2

The End.