#include<stdio.h>
struct node
{
int data;
struct node *next;
};
struct node *insert_end(struct node *);
struct node *delete(struct node *);
void display(struct node *);
int main()
{
struct node *start=NULL;
struct node *tmp;
int i;
for(i=0;i<5;i++)
{
tmp=(struct node *)malloc(sizeof(struct node));
tmp->data=4-i;
tmp->next=start;
start=tmp;
}
printf("current list:");
display(start);
start=insert_end(start);
printf("\nnode after insertion at end:");
display(start);
start=delete(start);
}
struct node *insert_end(struct node *start) //inserts node at end of the lis
{
int data;
printf("insert data(node) to be inserted at end");
scanf("%d",&data);
struct node *tmp;
tmp=(struct node *)malloc(sizeof(struct node));
tmp->data=data;
tmp->next=NULL;
struct node *p=start;
if(p==NULL)
{
p->next=tmp;
return p;
}
while(p->next!=NULL)
p=p->next;
p->next=tmp;
return start;
}
struct node *delete(struct node *start) //deletes the desired node
{
int x;
printf("insert the node to be deleted");
scanf("%d",&x);
struct node *tmp=start, *prev;
if(start->data==x)
{
start=start->next;
free(tmp);
return start;
}
while(tmp!=NULL && tmp->data!=x)
{
prev=tmp;
tmp=tmp->next;
}
if(tmp==NULL)
{
printf("node to be deleted is not present in the list\n");
return start;
}
prev->next=tmp->next;
free(tmp);
printf("\nnode after deletion:");
display(start);
return start;
}
void display(struct node *start)
{
struct node *p;
if(start==NULL)
{
printf("Empty\n");
return;
}
p=start;
while(p!=NULL)
{
printf("%d->",p->data);
p=p->next;
}
printf("\n\n");
}
. The topic of this laboratory exercise a probably one of the most ieceresting ones you...
In this exercise, you will make a struct that contains x and y coordinates: struct point {int x; int y;}; The object of this exercise is to make a singly linked list of these point structures. Add one more member called "next" to your point struct. It is a pointer to the next member of the linked list. The next member of the last point struct should point to NULL, which indicates the end of the list. Your program will...
Introduction: One of the most important uses of pointers is for dynamic allocation of memory. In C++ there are commands that let the user request a chunk of memory from the operating system, and use this memory to store data. There are also commands to return memory back to the O/S when the program is finished using the data. In this lab, we will explore some of the things that can go wrong when using dynamic memory and discuss how...
Your assignment is to create and test a class for a queue of objects. You may use any object class of your choice as the data for the queue. The instances of the class should have at least one field that distinguishes each instance from other instances of the class (key property, also called a key field). You should complete the software to implement and test your queue and submit the software along with a project report. Your queue class...
I need this in C++. This is all
one question
Program 2: Linked List Class For this problem, let us take the linked list we wrote in a functional manner in a previous assignment and convert it into a Linked List class. For extra practice with pointers we'll expand its functionality and make it a doubly linked list with the ability to traverse in both directions. Since the list is doubly linked, each node will have the following structure: struct...
Project Description: In this project, you will combine the work you’ve done in previous assignments to create a separate chaining hash table. Overview of Separate Chaining Hash Tables The purpose of a hash table is to store and retrieve an unordered set of items. A separate chaining hash table is an array of linked lists. The hash function for this project is the modulus operator item%tablesize. This is similar to the simple array hash table from lab 5. However, the...
C
program
Main topics: Files Program Specification: For this assignment, you need only write a single-file C program. Your program will: Define the following C structure sample typedef struct int sarray size; the number of elements in this sanple's array floatsarray the sample's array of values sample Each sample holds a variable number of values, all taken together constitute a Sample Point Write a separate function to Read a file of delimited Sample Points into an array of pointers to...
This lab, for which you may work in groups of two, will require you to use a C structure to hold a record of any kind of data, i.e., address book, library of books as with chapter 14, etc. These records will be held in dynamic memory using memory allocation (malloc) to create new memory and the function (free) to release memory created via (malloc). Do not use linked lists for this assignment, we are using dynamic memory allocation to...
In this project you will create a console C++ program that will have the user to enter Celsius temperature readings for anywhere between 1 and 365 days and store them in a dynamically allocated array, then display a report showing both the Celsius and Fahrenheit temperatures for each day entered. This program will require the use of pointers and dynamic memory allocation. Getting and Storing User Input: For this you will ask the user how many days’ worth of temperature...
C++ Project - Create a memory game in c++ using structs and pointers. For this exercise, you will create a simple version of the Memory Game. You will again be working with multiple functions and arrays. You will be using pointers for your arrays and you must use a struct to store the move and pass it to functions as needed. Program Design You may want to create two different 4x4 arrays. One to store the symbols the player is...
In this assignment, you will implement a Memory Management System(MMS). Using C Programming Language..... MAKE SURE YOU USE C PROGRAMMING Your MMS will handle all requests of allocation of memory space by different users (one thread per user) …. HINT(You will use Pthreads and Semaphores). Your MMS will provide the user with an interface for making memory requests and also for freeing up memory that is no longer needed by the user. One of the jobs of your memory management...