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

[CODE]struct PCB* handleProcessArrival_PP(struct PCB *processhead,struct PCB *processtail,struct PCB *currProcess,struct PCB *newProcess,int currTime){ if(currProcess==NULL){ newProcess->executionStartTime = currTime; newProcess->executionEndTime = currTime+newProcess->totalBurstTime; newProcess->remainingBurstTime = newProcess->totalBurstTime; if(newProcess->processID==processhead->processID){ processhead= newProcess->next; printf("processhead in case 1 %d \n",processhead->processID); } currProcess=newProcess; printf("***current process = new process%d \n",currProcess->processID); contents(processhead); return currProcess; //return processhead; } if (currProcess->processID !=0){ contents(processhead); if(currProcess->processPriority>newProcess->processPriority){//new process higher priority printf("***new process in handle %d \n",newProcess->processID); currProcess->executionStartTime = 0; currProcess->executionEndTime = 0; currProcess->remainingBurstTime = currProcess->totalBurstTime-(currProcess->executionStartTime-currTime); processtail->next=currProcess; processtail=currProcess; newProcess->executionStartTime=currTime; newProcess->executionEndTime = currTime+newProcess->totalBurstTime; newProcess->remainingBurstTime = newProcess->totalBurstTime; currProcess=newProcess; printf("current process replaced with%d \n",newProcess->processID); printf("processhead in case 2 %d \n",processhead->processID); return currProcess; } if(currProcess->processPriority<newProcess->processPriority){//new process lower priority contents(processhead); newProcess->executionStartTime = 0; …

Member Avatar
Member Avatar
-1 forum 1

public Set<Product> getProductsByPriceFilter(Map<String, String> filterParams) { Set<Product> products = new HashSet<Product>(); String l = filterParams.get("low"); String h = filterParams.get("high"); BigDecimal floor = new BigDecimal(l); BigDecimal ceil = new BigDecimal(h); return products; } I have discovered an interesting phenomena. I have filterParams that should <String, String>. However, if I use filterParams.get with an existing key, it returns a Linked List. Where might be the issue? java.lang.ClassCastException: java.util.LinkedList cannot be cast to java.lang.String at com.packt.webstore.domain.repositoryImpl.ProductRepositoryImpl.getProductsByPriceFilter(ProductRepositoryImpl.java:103) Line 103 is String l = filterParams.get("low"); I've tried explicit conversion as well, but it doesn't seem to work.

Member Avatar
Member Avatar
+0 forum 8

Im trying to implement queue with a linked list i think i have the enqueue function correct but im having problems with the dequeue. I can get it to delete the first number but then the rest of the list is empty can someone point me in the right direction? #include <stdio.h> #include <string.h> #include <stdlib.h> //Structure node struct _node { int num; struct _node * next; }; //type definitions typedef struct _node node; typedef node * link; //Structure list struct _list { link top;//points to node structure link bottom; }; //type definition typedef struct _list list; typedef list * …

Member Avatar
Member Avatar
+0 forum 4

this is my latest class assignment, i would really appreciate some assistence with my pseudo code to help me in the right direction. my code skeleton is provided at the end of this post. Deque A double-ended queue, often abbreviated deque and pronounced deck, is an object with the following interface. public interface IDeque<E> { public void addFirst(E e); public void addLast(E e); public E removeFirst(); public E getFirst(); public boolean isEmpty(); } A deque is a list of items with restrictions on how it can be manipulated. Items can be added to either end of the list but can …

Member Avatar
Member Avatar
+0 forum 5

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

Member Avatar
Member Avatar
+0 forum 10

I'm trying to create a sorted linked list without using Collections. I don't want to use Collections since I'd like to learn how to work with Linked List manually. I'm getting NullPointer exception when I'm comparing strings and comparison <0. Any suggestions and help are appreciated. This is the part where the exception is triggered: if (comp<0) { last.next = new Link(); //here the exception is triggered last.next.next = next; } Here's the full code: class Link { public String info; public Link next; public Link(String info) {this.info=info;} public Link(){} } public class List { public static void main(String[] args) …

Member Avatar
Member Avatar
+0 forum 5

I'm having a problem with my linked list. I want to add to the beginning of the list and delete from the beginning of the list. I get an AccessViolation which is coming from where I print out the list. I also don't think it's adding elements to the linked list, it just overwrites whats there already. I don't know if the delete function works but when I run it, I get a NullPointer Exception. #include <StdAfx.h> #include <stdio.h> #include <stdlib.h> typedef struct Node{ // This struct is complete. Do not change it. int num; struct Node *next; } Rec; …

Member Avatar
Member Avatar
+0 forum 3

Node inside a linkedlist SomeInterface has an addLast() method that should add a node at the end of the list public LinkedList<T> implements SomeInterface<T>{protected class Node<T>{ privateT data; private Node<T> head,tail; protected Node(T data,Node<T>tail){ this.data=data;head=null;this.tail=tail;} private T getInfo(){return this.data;} private void setTail(Node<T>newTail){this.tail=newTail;} private void setLink(Node<T>newHead){this.head=newHead;} private Node<T> getLink(){return tail;} }} public void addLast(){ } }//end of LinkedList<T> class when I create a LinkedList object (`LinkedList<String>somelist=new LinkedList<T>()`) and try to append multiple items (`somelist.append("William");somelist.append("Fredk rick"`);somelist.append(`Maria`)) only the last item/string gets appended to the list. Any reason why?

Member Avatar
Member Avatar
+0 forum 2

I'm trying to implement a hangman game using linked lists but not getting anywhere. I want guessed characters to be inserted in a Linked list of chars at a position that corresponds to the character's position in the word they are trying to guess.(See example at bottom.) For some reason my play() method doesn't do what it's supposed to do. 1. I have a gameLinkedList class that takes in a word; creates a charNode reference (character node) and a LinkedList of charNodes with their info set to the '_' character. the size of the linked list is equal to the …

Member Avatar
Member Avatar
+0 forum 1

hello fellow programmers, i am doing an assignment for class and i am having a bit of trouble. So the assignments reads Given two sorted (in ascending order) lists of size M and N, write an O(M+N) algorithm to find the sorted (also in ascending order) union of the two lists. Assume each list contains no duplicate items. I know that i want to use a MergeSort to merge the two lists together, i just dont know how to write in code. So far i have: template<typename T> list<T> listUnion(const list<T>& one, const list<T>& two) { list<T> result; std::list<T>::iterator modifIter; …

Member Avatar
Member Avatar
+0 forum 3

I have to accept user input, a string, into a doubly linked list and print the output reversed and forward. My professor gave us the following program and told us to modify it. However, I cannot figure it out. /* Program to reverse a doubly linked list */ #include <stdio.h> #include <stdlib.h> /* a node of the doubly linked list */ struct node { int data; struct node *next; struct node *prev; }; /* Function to reverse a Doubly Linked List */ void reverse(struct node **head_ref) { struct node *temp = NULL; struct node *current = *head_ref; /* swap next …

Member Avatar
Member Avatar
+0 forum 1

I want to know how I can implement a function to open a file and read its contents into a linked list, and then print the contents reversed #include <stdio.h> typedef struct stack { char b[100]; int top; }stack; void push(stack *s,char k) { if(s->top==99) printf("\n Stack is full "); else s->b[++s->top]=k; } char pop(stack *s) { char c; if(s->top==(-1)) printf("\n Stack is empty"); else c=s->b[s->top--]; return c; } void main() { char name[100]; stack s; system("clear") ; s.top=-1; printf("\nEnter name :"); gets(name); int i=0; while(name[i]!='\0') { push(&s,name[i]); i++; } printf("\n Reverse string is :"); while(s.top!=-1) { printf("%c",pop(&s)); } getchar(); …

Member Avatar
Member Avatar
+0 forum 4

In my Advanced Data Structures class we have an assignment to implement a linked list using arrays. One array holds the data item, while another contains a reference to the next item. I'm not really sure about how to add/remove items. // **************************************************** // Reference-based implementation of ADT list using arrays. // Due to the limitations with array of generics, the // "data type" for the list items is fixed to be of type // PageUsage. Any program using this class must specify // <PageUsage> as the value for the type parameter. // **************************************************** public class List<T> { // reference …

Member Avatar
Member Avatar
+0 forum 8

import java.util.*; public class List { public static INode head; public List() { head = new INode(8); } public static void main (String[] args) { INode a = new INode(8); int data = a.getValue(); System.out.println(data); System.out.println(head.getValue()); } } And my Node class: public class INode { private int value; private INode right, down; private int row, col; public INode(int value) { this.value = value; } public int getValue() { return value; } public void setValue(int value) { this.value = value; } public INode getRight() { return right; } public void setRight(INode right) { this.right = right; } public INode getDown() …

Member Avatar
Member Avatar
+0 forum 2

hi all, I am working on C++ coding of fault simulation algorithm of a digital circuit . The first step involves parsing of netlist files. The sample netlist looks like - # Only 2,3 input gates considered ... INPUT(1) INPUT(2) INPUT(3) INPUT(6) INPUT(7) OUTPUT(22) OUTPUT(23) # comment here 10 = NAND(1, 3) 11 = NAND(3, 6) 16 = NAND(2, 11) 19 = NAND(11, 7) 22 = NAND(10, 16) 23 = NAND(16, 19) INPUT are the primary inputs, OUTPUT are the primary outputs, gates are the intermediate nodes. I hope some of you can imagine how this circuit will look like …

Member Avatar
Member Avatar
+0 forum 2

ran into a little snag with my code. i am trying to push the data of all the nodes in a linkedlist into a stack. problem is, i have no idea how to properly convert a node into a variable. Node current = list.returnHeadNode(); //other code... stack.push(current.getData()); my error lies in here somewhere. can someone explain to me why this does not work and what i can do to fix it?

Member Avatar
Member Avatar
+0 forum 2

#include <stdio.h> #include <malloc.h> struct node { int data; struct node *link; }; void append (int data, struct node **s) { struct node *p, *q; if (*s == NULL) { p = (struct node *) malloc (sizeof (struct node)); p->data = data; p->link = NULL; *s = p; return; } q = *s; p = (*s)->link; while (p != NULL) { q = p; p = p->link; } q->link = (struct node *) malloc (sizeof (struct node)); q->link->data = data; q->link->link = NULL; return; } void insertion_sort (struct node *s) { int i, j; struct node *temp = s, *r; …

Member Avatar
Member Avatar
+0 forum 4

hi, i am trying out past year questions for a resit and am stuck with the question below. Question 1 In the following you may assume the existence of the ListIterator<e> interface and LinkedList<E> class with the following methods public interface ListIterator<E> { E next(); boolean hasNext(); } public class LinkedList<E> { public void addLast(E obj){..} public int size(){..} public ListIterator<E> listIterator(){...} } Finished the design of the printBackward method given below using the methods listed above in the ListIterator<E> interface and LinkedList<E> class. You should not introduce any new variable tinto the method. In your answer, do not copy …

Member Avatar
Member Avatar
+0 forum 10

i want to append a node in the linked list when i append this as struct node*p; p=NULL; append(p,1); where function is declared as append(struct node*q int num) i append three node, after this i call the function for counting the node, i get the total no node is 0, while i have appended the node. what is the error... please help me...

Member Avatar
Member Avatar
+0 forum 1

Hi everyone, I'm facing problem in deleting a node in **del()** used in my program. Suppose, i've added a city as **Delhi**, and at the time of deleting, i type the name as **delhi**, the compiler gives a processor fault. But, i want it to display the line number **95**. I found out that there is error in while part in line number **85**, but i dont know how to overcome that problem. Anyone there to help me out with this???????????????????????? NOTE: I dont want to use any extra integer to detect the position. My program: #include<conio.h> #include<stdio.h> #include<string.h> #include<alloc.h> …

Member Avatar
Member Avatar
+0 forum 8

Hi, I'm a new java user, working on a brute-force knights tour algorithm in linkedlist. The move function worked perfectly (for a while), I mean, the pointer could move forward, or backward if a wrong path was chosen. But all of a sudden, it returned me a stackoverflow error. i'm really confused, can anyone help me? (I'm pretty sure that everything else was done correctly except for the following function) I know my code is kinda tedious but since it is mostly repeating, it would not take you too long to read it. I really appreciate your help and your …

Member Avatar
Member Avatar
+0 forum 1

I have pretty much failed my class (4 weeks behind in an 8 week class that is currenlty at the beginning of week 8), but I am wanting to learn C++ for myself anyhow. I have visited http://www.cplusplus.com/doc/tutorial/ and gone through the tutorial, but cannot understand this assignment. I have a working address book that was created using an array (SEVERAL .h and .cpp files are used). The first part of the assignment is to edit the files to use a linked list instead of an array. After editing to use a linked list, I need to add funtions to …

Member Avatar
Member Avatar
+0 forum 3

Hello, I just need some help with linkedlists in C#, linked-list in C++ is kinda easy with pointers but im facing some problems in C# I read the examples provided on http://msdn.microsoft.com but I couldn't figure out how to link two different linked lists the efficitent way seems to be having LinkedListNode into a linked list , so lets say I have two linked lists LinkedList<String> L1 = new LinkedList<String>(); LinkedList<String> L2 = new LinkedList<String>(); and then lets say I have the following nodes LinkedListNode<String> Ln1 = new LinkedListNode<String>("Orange"); LinkedListNode<String> Ln2 = new LinkedListNode<String>("Banana"); LinkedListNode<String> Ln3 = new LinkedListNode<String>("Apple"); LinkedListNode<String> …

Member Avatar
Member Avatar
+0 forum 3

I have a GUI in which has a container for a JTable called 'listTable'. I want to populate the JTable with data stored in a linked list, using the AbstractTableModel. Basically, I have a LinkedList stored in Processing.java. It contains all the data retrieved from a text file. I created an AbstractTableModel to tell the JTable how to be populated. What I want to do now is to populate the JTable in GUI_g with "the contents of the linkedlist". Anyone can tell me how to do this? Here is the code: GUI_g: import java.awt.*; import javax.swing.*; import javax.swing.JTable; import java.util.List.*; …

Member Avatar
Member Avatar
+0 forum 1

I have the program working up to the point where at the end of every test it fails and get. where do I need to look to start fixing the failed tests.(files are attached at the bottom) This is my output: START OF TEST 1: Testing insert, attach, and the constant member functions (4 points). Starting with an empty sequence. Testing that size() returns 0 ... Passed. Testing that is_item() returns false ... Passed. I'll call start() and look at the items one more time... All tests passed for this sequence. I am now using attach to put 10 into …

Member Avatar
Member Avatar
-1 forum 5

I have a Product class that is the parent of 3 other classes; Books, Movies, Music. And the Product class connects to the Store class that holds the Store's location. If I need to find a certain Product I have to traverse the list of each the Store class and the Product class. However, my code is throwing a NullPointerExeption. When I debug it shows that pHead = null. I am thinking the error is within my addProductBook method and is not appointing the first product to head? Or my findProduct method holds the error. My constructor and addProductBook is …

Member Avatar
Member Avatar
+0 forum 1

Hey, I created a phone directory program. But I was wondering if I could get some hints on how I could create a txt file and add, delete names and numbers on the txt file. [CODE]import java.util.*; import java.lang.*; import java.lang.Object; import jpb.*; public class PhoneDir { private static LinkedList phone; public static void main(String[] args) { //Display commands System.out.println("List of Commands:\n" + " a - Show 'a'll records\n" + " d - 'd'elete the current record\n" + " f - change the 'f'irst name in current record\n" + " l - change the 'l'ast name in current record\n" + …

Member Avatar
Member Avatar
+0 forum 9

I'm new to c++. I was studying data structures and came to know Linked Lists Lately. We had a problem of finding an item stored inside a linked list and here's the code I wrote using Visual Studio to store and find an item. This code gives me a run time error. [COLOR="Red"]1. "Link.h" file[/COLOR] [CODE] #pragma once class Link { public: double num; char nam[20]; Link* next; Link(double pnum,char pnam[]); void displayLink(); }; [/CODE] [COLOR="Red"]2. "Link.cpp" file[/COLOR] [CODE] #include "StdAfx.h" #include "Link.h" #include<iostream> #include<cstring> using namespace std; Link::Link(double pnum,char pnam[]) { next = NULL; num = pnum; strcpy(nam,pnam); } …

Member Avatar
Member Avatar
+0 forum 2

[CODE]#include<iostream> #include<string> #include<conio.h> using namespace std; struct node{ int num,ages; string name,skills; struct node *link; }; typedef struct node *nodepointer; nodepointer add(nodepointer &head, int nu, int age); void str(nodepointer &head, string na, string ski); void DeleteFront(nodepointer &head); void display(nodepointer head); int main(){ nodepointer head = NULL; int c,nu,age; string na,ski; do{ up: system("CLS"); cout<<"[1]Add wizard"<<endl; cout<<"[2]Delete wizard"<<endl; cout<<"[3]Search wizard"<<endl; cout<<"[4]Display wizard"<<endl; cout<<"[5]Exit"<<endl; cout<<"Choose from numbers 1-5"<<endl; cin>>c; switch(c) { case 1: cout<<"Enter number: "<<endl; cin>>nu; head = add(head,nu,age); cout<<"Enter age: "<<endl; cin>>age; head = add(head,nu,age); cout<<"Enter name: "<<endl; cin>>na; str(head,na,ski); cout<<"Enter skill: "<<endl; cin>>ski; goto up; getch(); break; case 2: …

Member Avatar
Member Avatar
+0 forum 3

The End.