- Joined
- May 2, 2005
i'm close to completing the code, i'm just not sure how to go through my list and delete the mth element. Here is what I have so far, any help would greatly be appreciated.
#include <iostream>
using namespace std;
struct Node
{
int info;
Node * next;
};
void DeletNode(Node * PrevNode);
void Print(Node * first, Node * last);
void DeleteNode(Node * PrevNode);
int main()
{
int n, m;
Node * first = NULL;
Node * last = NULL;
Node * temp = NULL;
Node * temp2;
cout << "Enter Size Of List: ";
cin >> n;
cout << "Enter Interval: ";
cin >> m;
first = new Node;
first -> info = n;
first -> next = first;
last = first;
for(int i = n - 1;i > 0;i--)
{
temp = new Node;
temp -> info = i;
temp -> next = first;
first = temp;
last -> next = first;
}
Print(first,last);
return 0;
}
void Print(Node * first, Node * last)
{
Node * temp;
for(temp = first;temp != last;temp=temp->next)
{
cout << temp -> info << " -> ";
}
cout << temp -> info << endl;
}
void DeleteNode(Node * PrevNode)
{
Node * temp;
temp = PrevNode -> next;
PrevNode -> next = temp -> next;
delete temp;
}
#include <iostream>
using namespace std;
struct Node
{
int info;
Node * next;
};
void DeletNode(Node * PrevNode);
void Print(Node * first, Node * last);
void DeleteNode(Node * PrevNode);
int main()
{
int n, m;
Node * first = NULL;
Node * last = NULL;
Node * temp = NULL;
Node * temp2;
cout << "Enter Size Of List: ";
cin >> n;
cout << "Enter Interval: ";
cin >> m;
first = new Node;
first -> info = n;
first -> next = first;
last = first;
for(int i = n - 1;i > 0;i--)
{
temp = new Node;
temp -> info = i;
temp -> next = first;
first = temp;
last -> next = first;
}
Print(first,last);
return 0;
}
void Print(Node * first, Node * last)
{
Node * temp;
for(temp = first;temp != last;temp=temp->next)
{
cout << temp -> info << " -> ";
}
cout << temp -> info << endl;
}
void DeleteNode(Node * PrevNode)
{
Node * temp;
temp = PrevNode -> next;
PrevNode -> next = temp -> next;
delete temp;
}