this is a basic linklist,there seems to be a runtime error when i run the program(the main function) i suspect it has something to do with my del function
but i see nothing wrong can you help.Thanx - #include <iostream>
-
#include <iostream>
-
#include <string>
-
#include <stdio.h>
-
#include <stdlib.h>
-
#include <time.h>
-
#include <fstream>
-
using namespace std;
-
class linklist
-
{
-
private:
-
-
struct node
-
{
-
char data;
-
int line;
-
node *link;
-
}*p;
-
-
public:
-
-
linklist();
-
void append( char num ,int line);
-
void add_as_first( char num,int line );
-
void addafter( int c, char num,int line );
-
void del( char num );
-
void display();
-
char charat(int x);
-
int lineat(int x);
-
int count();
-
~linklist();
-
};
-
-
linklist::linklist()
-
{
-
p=NULL;
-
}
-
-
void linklist::append(char num,int line)
-
{
-
node *q,*t;
-
-
if( p == NULL )
-
{
-
p = new node;
-
p->data = num;
-
p->line=line;
-
p->link = NULL;
-
}
-
else
-
{
-
q = p;
-
while( q->link != NULL )
-
q = q->link;
-
-
t = new node;
-
t->data = num;
-
t->line=line;
-
t->link = NULL;
-
q->link = t;
-
}
-
}
-
-
void linklist::add_as_first(char num,int line)
-
{
-
node *q;
-
-
q = new node;
-
q->data = num;
-
q->line=line;
-
q->link = p;
-
p = q;
-
}
-
-
void linklist::addafter( int c, char num,int line)
-
{
-
node *q,*t;
-
int i;
-
for(i=0,q=p;i<c;i++)
-
{
-
q = q->link;
-
if( q == NULL )
-
{
-
cout<<"\nThere are less than "<<c<<" elements.";
-
return;
-
}
-
}
-
-
t = new node;
-
t->data = num;
-
t->line=line;
-
t->link = q->link;
-
q->link = t;
-
}
-
-
void linklist::del( char num )
-
{
-
node *q,*r;
-
q = p;
-
if( q->data == num )
-
{
-
p = q->link;
-
delete q;
-
return;
-
}
-
-
r = q;
-
while( q!=NULL )
-
{
-
if( q->data == num )
-
{
-
r->link = q->link;
-
delete q;
-
return;
-
}
-
-
r = q;
-
q = q->link;
-
}
-
cout<<"\nElement "<<num<<" not Found.";
-
}
-
-
void linklist::display()
-
{
-
node *q;
-
cout<<endl;
-
-
for( q = p ; q != NULL ; q = q->link )
-
cout<<endl<<q->data<<'\n'<<q->line;
-
-
}
-
int linklist::lineat(int x){
-
node *q;
-
int num;
-
q=p;
-
for(int i=0;i<=x;i++){
-
num=q->line;
-
q=q->link;
-
}
-
return num;
-
}
-
char linklist::charat(int x){
-
node *q;
-
char num;
-
q=p;
-
for(int i=0;i<=x;i++){
-
num=q->data;
-
q=q->link;
-
}
-
return num;
-
}
-
int linklist::count()
-
{
-
node *q;
-
int c=0;
-
for( q=p ; q != NULL ; q = q->link )
-
c++;
-
-
return c;
-
}
-
-
linklist::~linklist()
-
{
-
node *q;
-
if( p == NULL )
-
return;
-
-
while( p != NULL )
-
{
-
q = p->link;
-
delete p;
-
p = q;
-
}
-
}
-
int main(){
-
int x;
-
linklist l;
-
l.append('1',1);
-
l.append('2',2);
-
l.append('5',10);
-
l.del('2');
-
l.display();
-
cout<<l.lineat(2);
-
cin>>x;
-
}
-
2 2106
The loop in linklist::linea t is running to i<=x when it shoudl run to i<x.
The crash is not in your destructor but in linklist::linea t.
A simple debugger session would have found this.
thanx man.Really appreciate it.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: jova |
last post by:
I'm stuck
I have to convert an array to a linklist
the array is initialized as
public Organization{
Crew members = new Member
etc....
|
by: vjay |
last post by:
I want to just create a linklist.The program below goes into an endless
loop.The srange behaviour is that i can exit from the program if i create
only two nodes.After two goes into infinite loop.
#include<stdio.h>
#include<stdlib.h>
struct node
{
int data;
|
by: jwvai316 |
last post by:
I don't really know how to say it so I just say it a nested linklist.
How do you make LinkLists inside LinkList?
Can anyone help me for this?
I think an example program will help me a lot.
thank you.
|
by: prashant0903 |
last post by:
how i 'll made the linklist program in java both included insertion & deletion in program
|
by: Asembereng |
last post by:
Hi i want to do insertion sort, merge sort and quick sort on my
linkList of ints.. do anyone have an idea how to do it??
these are the codes. And i also need to define a lifo fifo class..
class UTGLLElement {
public int myData; // data item
| |
by: zubia |
last post by:
hi
how 2 deal with the rptr n lptr in doubly linklist
|
by: smoothkriminal1 |
last post by:
the question is u read timetable of 40 students from file n den find da slot where all fourty students dnt hve clash...if any....
may b i ll be able to make clash logic but i m even just nt getting how to pick timetable data from file using linklist
file can b of any format there shud b six days n 6 lecture a day(maximum)
plz help me for coding this problem
|
by: smoothkriminal1 |
last post by:
Write a Code that will pick timetable of 40 students from file using linklist n than find a slot where all the students dont have any class.
file can be of any format
Student can maximum take 6 lectures a day consist of 90mins each.
I have not tried this problem yet becuase i dont know how to get data from file using linklist.
Dnt give me a code for getting data from file but atleast give me idea how to get data from file so that i become...
|
by: Parul Bagadia |
last post by:
I have written a code for deleting certain value from linklist;
it's not working; where as i have written one for deleting a no., after given no. which works fine! I even debugged it; but invain;
down here am posting my code; please somebody who can point it out; let me know fast; whats wrong in it...
//Delete a number next to the given number
void afterdelete()
{
struct linklist*temp=NULL;
int no=0;
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |