|
i did not understand anything you said. And whats that code C++?
|
|
|
|
|
if you don't want to sort:
for each node, Cur
for each node, Temp
if Temp!=Cur
if Temp.value==Cur.value, duplicate
Temp=Temp.next
Cur=Cur.next
basically, for each node, you compare its value to every other node. it's inefficient, but it will work.
you can also sort your list when you add:
1. walk the list, find the first node with a value greater than the new value. this is 'Cur'
2. change the next pointer of Cur->prev to point to your new node.
3. set your new node's prev to Cur->prev. now you're all linked in the prev direction.
4. change the prev pointer of Cur to point to your new node.
5. set your new node's cur to point to Cur. now you're all linked in the next direction.
that way, the list is always sorted, and you can just walk it, looking for duplicates.
|
|
|
|
|
OK, I decided to sort the list, but can you tell me why is not working well?
|
|
|
|
|
TCPMem wrote: How to sort a list???
Insert the items in their "sorted" position within the list.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Some people are making such thorough preparation for rainy days that they aren't enjoying today's sunshine." - William Feather
|
|
|
|
|
for(int i = 1; i < N; i++)
for(int j = N - 1; j >= i; j--)
if(p->key > p->next->key)
{
t = p->key;
p->key = p->next->key;
p->next->key = t;
}
Here is the sort but it doesn' t work
|
|
|
|
|
first problem: you're never moving p
|
|
|
|
|
|
p = p->next;
p = p->prev; (forgot you're inserting at the beginning, not at the end of list)
if (p==NULL) bail.
|
|
|
|
|
OK, here is the full code that I' m working on. Can you tell me my mistakes exactly because I can' t understand where to put what. The UniqueList function is important, which now only shows the list and nothing more. The sort does not work...
#include "iostream"
using namespace std;
void Add(int n);
void UniqueList(int N);
struct Elem
{
int key;
Elem *prev;
Elem *next;
} *start;
int main()
{
int num;
int N = 0;
start = NULL;
while(cin >> num)
{
Add(num);
N++;
}
cout << endl;
UniqueList(N);
return 0;
}
void Add(int n)
{
Elem *p = start;
start = new Elem;
start->key = n;
start->next = p;
start->prev = NULL;
if(NULL != p) p->prev = start;
}
void UniqueList(int N)
{
Elem *p = start;
int t;
if(NULL != start) cout << "List:" << endl;
else cout << "Empty list!";
for(int i = 1; i < N; i++)
for(int j = N - 1; j >= i; j--)
{
if(p->key > p->next->key)
{
t = p->key;
p->key = p->next->key;
p->next->key = t;
}
}
while(NULL != p)
{
cout << p->key << endl;
p = p->next;
}
}
|
|
|
|
|
|
maybe it's best to rethink this from the beginning.
if your goal is to have a list with no duplicates, the easiest thing to do is to simply not add duplicates.
so, every time, you go to add a new Elem, walk through your list and see if you already have an Elem with that key. if you do, don't add anything.
to do that, you need a function that can walk through the list and look for an Elem with a given key:
bool haveKey(Elem *p, int k)
{
while (p!=NULL)
{
if (p->key=k) return true;
p = p->next;
}
return false;
}
just call that at the top of your Add. if it returns false, don't add anything.
|
|
|
|
|
No, the assignment is to add duplicates, but when show the list to show it without them. I think the sort thing will do the job but can' t do it properly.
modified on Monday, April 18, 2011 4:57 PM
|
|
|
|
|
ok, then i would recommend sorting the nodes on input. it is far more efficient than sorting the whole list, and it's actually fairly straightforward. (i outlined it above)
unfortunately, i have to leave for the day. so.. good luck!
|
|
|
|
|
I posted a question on the quick questions and answers board and I got some helpful advice. Here's the link: Where-to-look-for-my-project-goal[^]
This will give you the basics of my goal. Any way I created a blog to chronicle my progress toward that goal and would like some input from time to time on my blog to help me along in the learning process. Please bear in mind that I am a novice and am completely self taught through trial an error with mostly error. Now I have decided to stop dabbling and blundering through trying to learn programming and actually learn something useful.
What I need at this point are helpful comments and nudges that will point me in the right direction or let me know if I am getting it. My project is very ambitious to say the least and is probably impossibly high but is my motivation to learn.
Ok enough babbling here's the link to my blog: thegreatproject.wordpress.com[^]
|
|
|
|
|
Hi All,
I am tring to write an application that open a web page and Copy its data to the clipboard.
I know i can use function to httpRead the page into a buffer, but in this case i have all the html's tags
and i do not need them, if i use copy (CTRL+C) i am able to only get the text.
I thought to open an IE process with the url as parameter and then use the SendMessage API with the process handle and the CTRL+A as the message and then CTRL+C as the message (hopefully it will generate a Select All and Copy).
If this works would it be able to work when the user is logout (no visible UI).
Love to hear your thought about it, i am working with C++ or C# on windows.
Thanks a lot for your time,
Ram.
modified on Wednesday, April 20, 2011 2:11 AM
|
|
|
|
|
Ram Shmider wrote: and i do not need them, if i use copy (CTRL+C) i am able to only get the text.
Can you parse the HTML content using some class for ex: HTML Reader C++ Class Library[^]
You talk about Being HUMAN. I have it in my name
AnsHUMAN
|
|
|
|
|
|
Hi Ram,
This is possible and your thinking is correct. Only you need is to get focus to the browser control then simulate the Ctrl+A and Ctrl+C using SendInput API. So in your code you need to wait for the browser window to appear and find the browser control then give focus to that by sending SetFocus. now simulate the keystrokes. But there always a chance for something unexpected results since any other window activation will make your task difficult.
hope this helps
Nitheesh George
http://www.simpletools.co.in
|
|
|
|
|
Thanks a lot for the help, it realy helps... by using SendInput i was able to solved it.
This is a the part code i use...(C++)
INPUT input;
input.type = INPUT_KEYBOARD;
// ctrl down
input.ki.wVk = VK_LCONTROL;
input.ki.dwFlags = 0;
SendInput(1, &input, sizeof(INPUT));
Sleep(50);
// C down
input.ki.wVk = 'C';
SendInput(1, &input, sizeof(INPUT));
Sleep(50);
// C up
input.ki.dwFlags = KEYEVENTF_KEYUP;
SendInput(1, &input, sizeof(INPUT));
Sleep(50);
// Ctrl up
input.ki.wVk = VK_LCONTROL;
SendInput(1, &input, sizeof(INPUT));
Sleep(50);
To simulate the CTRL+A just update this part to 'A'
// A down
input.ki.wVk = 'A';
SendInput(1, &input, sizeof(INPUT));
Sleep(50);
Again,
Thanks a lot for the help.
Ram.
|
|
|
|
|
When I try running a Qt application with the following main.cpp file:
#include <QApplication>
#include "ui_checkabder.h"
#include <QDialog>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
Ui::CheckAbder ui;
QDialog *dialog = new QDialog;
ui.setupUi(dialog);
dialog->show();
return app.exec();
}
I get the following errors:
c:/QtSDK/Desktop/Qt/4.7.3/mingw/lib/libqtmaind.a(qtmain_win.o):-1: In function `WinMain@16':
c:/ndk_buildrepos/qt-desktop/src/winmain/qtmain_win.cpp:131: error: undefined reference to qMain(int, char **)
:-1: error: collect2: ld returned 1 exit status
And, abder.pro looks like this:
######################################################################
# Automatically generated by qmake (2.01a) Mon Apr 18 09:52:56 2011
######################################################################
TEMPLATE = app
TARGET =
DEPENDPATH += .
INCLUDEPATH += .
# Input
FORMS += checkabder.ui
How can I solve those errors? Provided that I'm using Qt Creator.
Thanks.
|
|
|
|
|
This is not really a C/C++ issue as such; you would probably get better help here[^].
|
|
|
|
|
|
Hi ,
I am using CabLib.Dll(8.1.0.0) file for compressing in .Net.
It works perfectly alright.
I am using cablib.CompressFolder method.
But if the file name consists of odd number of special character '%'(Percentage) it causes the application to crash.For even number of '%' its working fine.
Any ideas what might be the problem.It's working for file name with other special characters '@','#','$','&' n all.
If I use the latest cabLib.dll the application doesn't crashes but the compressed filename is not the desired one with a different name altogether.
for eg;
If I give the file name to be 90%.cab it crashes.(odd)
But if I give it as 90%%.cab(even) it works but the output file name will be 90%.cab
Is there anyway to overcome this situation.
Code Snippet:
1)CabLib.Compress compressProj = new CabLib.Compress();
2)compressProj.CompressFolder(this.workingFolder, configurationFile, "*.*", b_UtcTime, s32_SplitSize);
While debugging in .Net it crashes on the 2) line.
It shows the error : (Microsoft Visual C++ Runtime Error)
R6002 floating point support not loaded while saving
Could you please help us to sort-out the issue.
Regards
Tomy
|
|
|
|
|
Assuming that cablib is a Microsoft product you should report it to Microsoft support. It would appear (from your problem description) that filenames with '%' characters are being used in the format portion of print or format statements, giving the results that you see.
|
|
|
|
|
i want to drag and drop image in a listview item
|
|
|
|